Skip to content

Commit

Permalink
(fix) fall back to any type when array is of type any (#1244)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dummdidumm authored Nov 17, 2021
1 parent e642d9e commit b1b0484
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,13 @@ describe('DiagnosticsProvider', () => {
]);
});

it('falls back to any for each entry with checkJs without strict', async () => {
const { plugin, document } = setup(path.join('checkJs-no-strict', 'each-any.svelte'));
const diagnostics = await plugin.getDiagnostics(document);

assert.deepStrictEqual(diagnostics, []);
});

it('properly handles complex types for `each` blocks (diagnostics-each)', async () => {
const { plugin, document } = setup('diagnostics-each.svelte');
const diagnostics = await plugin.getDiagnostics(document);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
let anyType;
</script>

{#each anyType as anyEntry}
{anyEntry.asd()}
{/each}
2 changes: 1 addition & 1 deletion packages/svelte2tsx/svelte-shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ declare function __sveltets_1_awaitThen<T>(

declare function __sveltets_1_each<T extends ArrayLike<unknown>>(
array: T,
callbackfn: (value: T extends ArrayLike<infer U> ? U : never, index: number) => any
callbackfn: (value: T extends ArrayLike<infer U> ? U : any, index: number) => any
): any;

declare function __sveltets_1_createSvelte2TsxComponent<Props, Events, Slots>(
Expand Down

0 comments on commit b1b0484

Please sign in to comment.