Skip to content

Commit b1b0484

Browse files
authored
(fix) fall back to any type when array is of type any (#1244)
Fixes a overzealous check introduced through #1218 When checking JS, the check would infer the type of an array entry to unknown instead of any, when the type of the array was any
1 parent e642d9e commit b1b0484

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,13 @@ describe('DiagnosticsProvider', () => {
797797
]);
798798
});
799799

800+
it('falls back to any for each entry with checkJs without strict', async () => {
801+
const { plugin, document } = setup(path.join('checkJs-no-strict', 'each-any.svelte'));
802+
const diagnostics = await plugin.getDiagnostics(document);
803+
804+
assert.deepStrictEqual(diagnostics, []);
805+
});
806+
800807
it('properly handles complex types for `each` blocks (diagnostics-each)', async () => {
801808
const { plugin, document } = setup('diagnostics-each.svelte');
802809
const diagnostics = await plugin.getDiagnostics(document);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
let anyType;
3+
</script>
4+
5+
{#each anyType as anyEntry}
6+
{anyEntry.asd()}
7+
{/each}

packages/svelte2tsx/svelte-shims.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ declare function __sveltets_1_awaitThen<T>(
206206

207207
declare function __sveltets_1_each<T extends ArrayLike<unknown>>(
208208
array: T,
209-
callbackfn: (value: T extends ArrayLike<infer U> ? U : never, index: number) => any
209+
callbackfn: (value: T extends ArrayLike<infer U> ? U : any, index: number) => any
210210
): any;
211211

212212
declare function __sveltets_1_createSvelte2TsxComponent<Props, Events, Slots>(

0 commit comments

Comments
 (0)