From 993339807d3b590a7c1b1bb6ab99357923c40b75 Mon Sep 17 00:00:00 2001 From: GrygrFlzr Date: Sun, 14 Mar 2021 15:12:18 +0700 Subject: [PATCH 1/2] create-svelte types - Re-added globals.d.ts to JS template - Fixed globals.d.ts TSDoc notation - Added vite/client to types in js/tsconfig - Upped tsconfig target to es2018 - Enable checkJs in js/tsconfig --- .changeset/thin-grapes-dance.md | 5 ++ .../cli/modifications/add_typescript.js | 5 -- packages/create-svelte/template/globals.d.ts | 29 ++++++++++ packages/create-svelte/template/jsconfig.json | 3 ++ .../template/src/routes/index.svelte | 7 +-- .../ts-template/src/globals.d.ts | 54 ------------------- .../create-svelte/ts-template/tsconfig.json | 4 +- 7 files changed, 44 insertions(+), 63 deletions(-) create mode 100644 .changeset/thin-grapes-dance.md create mode 100644 packages/create-svelte/template/globals.d.ts delete mode 100644 packages/create-svelte/ts-template/src/globals.d.ts diff --git a/.changeset/thin-grapes-dance.md b/.changeset/thin-grapes-dance.md new file mode 100644 index 000000000000..ce071dfdb3e5 --- /dev/null +++ b/.changeset/thin-grapes-dance.md @@ -0,0 +1,5 @@ +--- +'create-svelte': patch +--- + +create-svelte: globals.d.ts TSDoc fixes, add vite/client types to js/tsconfig diff --git a/packages/create-svelte/cli/modifications/add_typescript.js b/packages/create-svelte/cli/modifications/add_typescript.js index 285d78a7429a..326812b2b335 100644 --- a/packages/create-svelte/cli/modifications/add_typescript.js +++ b/packages/create-svelte/cli/modifications/add_typescript.js @@ -17,7 +17,6 @@ export default async function add_typescript(cwd, yes) { update_component(cwd, 'src/routes/index.svelte', [[' + * + * ``` + */ +declare module '*.(gif|jpg|jpeg|png|svg|webp)' { + const value: string; + export = value; +} +//#endregion diff --git a/packages/create-svelte/template/jsconfig.json b/packages/create-svelte/template/jsconfig.json index 63baaaadd0d4..91cfb287968d 100644 --- a/packages/create-svelte/template/jsconfig.json +++ b/packages/create-svelte/template/jsconfig.json @@ -1,5 +1,8 @@ { "compilerOptions": { + "baseUrl": ".", + "checkJs": true, + "types": ["vite/client"], "paths": { "$app/*": [".svelte/dev/runtime/app/*", ".svelte/build/runtime/app/*"], "$components/*": ["src/components/*"] diff --git a/packages/create-svelte/template/src/routes/index.svelte b/packages/create-svelte/template/src/routes/index.svelte index de877f03844f..aefa46f8b234 100644 --- a/packages/create-svelte/template/src/routes/index.svelte +++ b/packages/create-svelte/template/src/routes/index.svelte @@ -5,13 +5,14 @@

Hello world!

- +

Visit the svelte.dev to learn how to build Svelte apps.

\ No newline at end of file + diff --git a/packages/create-svelte/ts-template/src/globals.d.ts b/packages/create-svelte/ts-template/src/globals.d.ts deleted file mode 100644 index ef3b4bfef94a..000000000000 --- a/packages/create-svelte/ts-template/src/globals.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -/// - -//#region Ensure Svelte file endings have a type for TypeScript -/** - * These declarations tell TypeScript that we allow import of Svelte files in TS files, e.g. - * ``` - import Component from './Component.svelte'; - ``` - */ -declare module '*.svelte' { - export { SvelteComponent as default } from 'svelte'; -} -//#endregion - -//#region Ensure image file endings have a type for TypeScript -/** - * These declarations tell TypeScript that we allow import of images, e.g. - * ``` - - - ``` - */ -declare module '*.gif' { - const value: string; - export = value; -} - -declare module '*.jpg' { - const value: string; - export = value; -} - -declare module '*.jpeg' { - const value: string; - export = value; -} - -declare module '*.png' { - const value: string; - export = value; -} - -declare module '*.svg' { - const value: string; - export = value; -} - -declare module '*.webp' { - const value: string; - export = value; -} -//#endregion diff --git a/packages/create-svelte/ts-template/tsconfig.json b/packages/create-svelte/ts-template/tsconfig.json index 9de39abd0475..ee1b54169ba4 100644 --- a/packages/create-svelte/ts-template/tsconfig.json +++ b/packages/create-svelte/ts-template/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "moduleResolution": "node", - "target": "es2017", + "target": "es2018", /** svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript to enforce using \`import type\` instead of \`import\` for Types. @@ -18,6 +18,8 @@ "forceConsistentCasingInFileNames": true, "baseUrl": ".", "allowJs": true, + "checkJs": true, + "types": ["vite/client"], "paths": { "$app/*": [".svelte/dev/runtime/app/*", ".svelte/build/runtime/app/*"], "$components/*": ["src/components/*"] From 4838a969d4374d227d517f6c0176ad6fc3661878 Mon Sep 17 00:00:00 2001 From: GrygrFlzr Date: Sun, 14 Mar 2021 15:51:30 +0700 Subject: [PATCH 2/2] Less restrictive typing --- packages/create-svelte/template/globals.d.ts | 1 + packages/create-svelte/template/jsconfig.json | 2 -- packages/create-svelte/ts-template/tsconfig.json | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/create-svelte/template/globals.d.ts b/packages/create-svelte/template/globals.d.ts index 2aa5af83387a..b7f4b33bf465 100644 --- a/packages/create-svelte/template/globals.d.ts +++ b/packages/create-svelte/template/globals.d.ts @@ -1,4 +1,5 @@ /// +/// //#region Ensure Svelte file endings have a type for TypeScript /** diff --git a/packages/create-svelte/template/jsconfig.json b/packages/create-svelte/template/jsconfig.json index 91cfb287968d..a229cc8cbe65 100644 --- a/packages/create-svelte/template/jsconfig.json +++ b/packages/create-svelte/template/jsconfig.json @@ -1,8 +1,6 @@ { "compilerOptions": { "baseUrl": ".", - "checkJs": true, - "types": ["vite/client"], "paths": { "$app/*": [".svelte/dev/runtime/app/*", ".svelte/build/runtime/app/*"], "$components/*": ["src/components/*"] diff --git a/packages/create-svelte/ts-template/tsconfig.json b/packages/create-svelte/ts-template/tsconfig.json index ee1b54169ba4..23c0bfa81779 100644 --- a/packages/create-svelte/ts-template/tsconfig.json +++ b/packages/create-svelte/ts-template/tsconfig.json @@ -19,7 +19,6 @@ "baseUrl": ".", "allowJs": true, "checkJs": true, - "types": ["vite/client"], "paths": { "$app/*": [".svelte/dev/runtime/app/*", ".svelte/build/runtime/app/*"], "$components/*": ["src/components/*"]