From b1b0484ccaa79f80c9d699c8a9fcb5ad30d230e5 Mon Sep 17 00:00:00 2001
From: Simon H <5968653+dummdidumm@users.noreply.github.com>
Date: Wed, 17 Nov 2021 08:44:27 +0100
Subject: [PATCH] (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
---
.../typescript/features/DiagnosticsProvider.test.ts | 7 +++++++
.../diagnostics/checkJs-no-strict/each-any.svelte | 7 +++++++
packages/svelte2tsx/svelte-shims.d.ts | 2 +-
3 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 packages/language-server/test/plugins/typescript/testfiles/diagnostics/checkJs-no-strict/each-any.svelte
diff --git a/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts b/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts
index a2dc1072b..8860fc2f3 100644
--- a/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts
+++ b/packages/language-server/test/plugins/typescript/features/DiagnosticsProvider.test.ts
@@ -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);
diff --git a/packages/language-server/test/plugins/typescript/testfiles/diagnostics/checkJs-no-strict/each-any.svelte b/packages/language-server/test/plugins/typescript/testfiles/diagnostics/checkJs-no-strict/each-any.svelte
new file mode 100644
index 000000000..ff088e6d2
--- /dev/null
+++ b/packages/language-server/test/plugins/typescript/testfiles/diagnostics/checkJs-no-strict/each-any.svelte
@@ -0,0 +1,7 @@
+
+
+{#each anyType as anyEntry}
+ {anyEntry.asd()}
+{/each}
diff --git a/packages/svelte2tsx/svelte-shims.d.ts b/packages/svelte2tsx/svelte-shims.d.ts
index f179c52b9..345e3819a 100644
--- a/packages/svelte2tsx/svelte-shims.d.ts
+++ b/packages/svelte2tsx/svelte-shims.d.ts
@@ -206,7 +206,7 @@ declare function __sveltets_1_awaitThen(
declare function __sveltets_1_each>(
array: T,
- callbackfn: (value: T extends ArrayLike ? U : never, index: number) => any
+ callbackfn: (value: T extends ArrayLike ? U : any, index: number) => any
): any;
declare function __sveltets_1_createSvelte2TsxComponent(