Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve create-svelte types #517

Merged
merged 3 commits into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thin-grapes-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

create-svelte: globals.d.ts TSDoc fixes, add vite/client types to js/tsconfig
5 changes: 0 additions & 5 deletions packages/create-svelte/cli/modifications/add_typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export default async function add_typescript(cwd, yes) {
update_component(cwd, 'src/routes/index.svelte', [['<script>', '<script lang="ts">']]);
add_svelte_preprocess_to_config(cwd);
add_tsconfig(cwd);
add_d_ts_file(cwd);

console.log(
bold(
Expand All @@ -37,10 +36,6 @@ function add_tsconfig(cwd) {
copy_from_ts_template(cwd, 'tsconfig.json');
}

function add_d_ts_file(cwd) {
copy_from_ts_template(cwd, 'src', 'globals.d.ts');
}

function copy_from_ts_template(cwd, ...path) {
fs.copyFileSync(join(__dirname, 'ts-template', ...path), join(cwd, ...path));
}
30 changes: 30 additions & 0 deletions packages/create-svelte/template/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/// <reference types="@sveltejs/kit" />
/// <reference types="vite/client" />

//#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.
* ```js
* 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
/**
* Tell TypeScript that we allow import of images, e.g.
* ```html
* <script lang='ts'>
* import successkid from 'images/successkid.jpg';
* </script>
* <img src="{successkid}">
* ```
*/
declare module '*.(gif|jpg|jpeg|png|svg|webp)' {
GrygrFlzr marked this conversation as resolved.
Show resolved Hide resolved
const value: string;
export = value;
}
//#endregion
1 change: 1 addition & 0 deletions packages/create-svelte/template/jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"$app/*": [".svelte/dev/runtime/app/*", ".svelte/build/runtime/app/*"],
"$lib/*": ["src/lib/*"]
Expand Down
1 change: 1 addition & 0 deletions packages/create-svelte/template/src/routes/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<h1>Hello world!</h1>

<Counter />

<p>Visit <a href="https://svelte.dev">svelte.dev</a> to learn how to build Svelte apps.</p>
</main>

Expand Down
54 changes: 0 additions & 54 deletions packages/create-svelte/ts-template/src/globals.d.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/create-svelte/ts-template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,6 +18,7 @@
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"allowJs": true,
"checkJs": true,
"paths": {
"$app/*": [".svelte/dev/runtime/app/*", ".svelte/build/runtime/app/*"],
"$components/*": ["src/components/*"]
Expand Down