From f5d853bfcf67f2bb57369d3be878c7a7dba175bb Mon Sep 17 00:00:00 2001 From: Ottomated Date: Thu, 19 Dec 2024 09:18:55 -0800 Subject: [PATCH 1/6] remove default function types for $props, $inspect, $bindable, and $host --- packages/svelte/types/index.d.ts | 92 +++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index 671f68bff72a..d422abebbc0f 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -2996,6 +2996,29 @@ declare namespace $effect { */ declare function $props(): any; +declare namespace $props { + // prevent intellisense from being unhelpful + /** @deprecated */ + export const apply: never; + /** @deprecated */ + // @ts-ignore + export const arguments: never; + /** @deprecated */ + export const bind: never; + /** @deprecated */ + export const call: never; + /** @deprecated */ + export const caller: never; + /** @deprecated */ + export const length: never; + /** @deprecated */ + export const name: never; + /** @deprecated */ + export const prototype: never; + /** @deprecated */ + export const toString: never; +} + /** * Declares a prop as bindable, meaning the parent component can use `bind:propName={value}` to bind to it. * @@ -3007,6 +3030,29 @@ declare function $props(): any; */ declare function $bindable(fallback?: T): T; +declare namespace $bindable { + // prevent intellisense from being unhelpful + /** @deprecated */ + export const apply: never; + /** @deprecated */ + // @ts-ignore + export const arguments: never; + /** @deprecated */ + export const bind: never; + /** @deprecated */ + export const call: never; + /** @deprecated */ + export const caller: never; + /** @deprecated */ + export const length: never; + /** @deprecated */ + export const name: never; + /** @deprecated */ + export const prototype: never; + /** @deprecated */ + export const toString: never; +} + /** * Inspects one or more values whenever they, or the properties they contain, change. Example: * @@ -3046,6 +3092,27 @@ declare namespace $inspect { * */ export function trace(name: string): void; + + // prevent intellisense from being unhelpful + /** @deprecated */ + export const apply: never; + /** @deprecated */ + // @ts-ignore + export const arguments: never; + /** @deprecated */ + export const bind: never; + /** @deprecated */ + export const call: never; + /** @deprecated */ + export const caller: never; + /** @deprecated */ + export const length: never; + /** @deprecated */ + export const name: never; + /** @deprecated */ + export const prototype: never; + /** @deprecated */ + export const toString: never; } /** @@ -3069,4 +3136,27 @@ declare namespace $inspect { */ declare function $host(): El; -//# sourceMappingURL=index.d.ts.map \ No newline at end of file +declare namespace $host { + // prevent intellisense from being unhelpful + /** @deprecated */ + export const apply: never; + /** @deprecated */ + // @ts-ignore + export const arguments: never; + /** @deprecated */ + export const bind: never; + /** @deprecated */ + export const call: never; + /** @deprecated */ + export const caller: never; + /** @deprecated */ + export const length: never; + /** @deprecated */ + export const name: never; + /** @deprecated */ + export const prototype: never; + /** @deprecated */ + export const toString: never; +} + +//# sourceMappingURL=index.d.ts.map From 3cc0245c7f502de24689a21b57d82f3adf169a34 Mon Sep 17 00:00:00 2001 From: Ottomated Date: Thu, 19 Dec 2024 09:21:58 -0800 Subject: [PATCH 2/6] changeset --- .changeset/three-suits-pay.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/three-suits-pay.md diff --git a/.changeset/three-suits-pay.md b/.changeset/three-suits-pay.md new file mode 100644 index 000000000000..51d46395e89e --- /dev/null +++ b/.changeset/three-suits-pay.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: Improve typescript DX for $inspect, $props, $bindable, and $host From aeda72d02f6b5f22a73db61e8ce9ef1528c3851b Mon Sep 17 00:00:00 2001 From: Ottomated Date: Thu, 19 Dec 2024 09:51:58 -0800 Subject: [PATCH 3/6] regenerate types --- packages/svelte/src/ambient.d.ts | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/packages/svelte/src/ambient.d.ts b/packages/svelte/src/ambient.d.ts index 4e98eb82eb9b..bb2a83810899 100644 --- a/packages/svelte/src/ambient.d.ts +++ b/packages/svelte/src/ambient.d.ts @@ -338,6 +338,29 @@ declare namespace $effect { */ declare function $props(): any; +declare namespace $props { + // prevent intellisense from being unhelpful + /** @deprecated */ + export const apply: never; + /** @deprecated */ + // @ts-ignore + export const arguments: never; + /** @deprecated */ + export const bind: never; + /** @deprecated */ + export const call: never; + /** @deprecated */ + export const caller: never; + /** @deprecated */ + export const length: never; + /** @deprecated */ + export const name: never; + /** @deprecated */ + export const prototype: never; + /** @deprecated */ + export const toString: never; +} + /** * Declares a prop as bindable, meaning the parent component can use `bind:propName={value}` to bind to it. * @@ -349,6 +372,29 @@ declare function $props(): any; */ declare function $bindable(fallback?: T): T; +declare namespace $bindable { + // prevent intellisense from being unhelpful + /** @deprecated */ + export const apply: never; + /** @deprecated */ + // @ts-ignore + export const arguments: never; + /** @deprecated */ + export const bind: never; + /** @deprecated */ + export const call: never; + /** @deprecated */ + export const caller: never; + /** @deprecated */ + export const length: never; + /** @deprecated */ + export const name: never; + /** @deprecated */ + export const prototype: never; + /** @deprecated */ + export const toString: never; +} + /** * Inspects one or more values whenever they, or the properties they contain, change. Example: * @@ -388,6 +434,27 @@ declare namespace $inspect { * */ export function trace(name: string): void; + + // prevent intellisense from being unhelpful + /** @deprecated */ + export const apply: never; + /** @deprecated */ + // @ts-ignore + export const arguments: never; + /** @deprecated */ + export const bind: never; + /** @deprecated */ + export const call: never; + /** @deprecated */ + export const caller: never; + /** @deprecated */ + export const length: never; + /** @deprecated */ + export const name: never; + /** @deprecated */ + export const prototype: never; + /** @deprecated */ + export const toString: never; } /** @@ -410,3 +477,26 @@ declare namespace $inspect { * https://svelte.dev/docs/svelte/$host */ declare function $host(): El; + +declare namespace $host { + // prevent intellisense from being unhelpful + /** @deprecated */ + export const apply: never; + /** @deprecated */ + // @ts-ignore + export const arguments: never; + /** @deprecated */ + export const bind: never; + /** @deprecated */ + export const call: never; + /** @deprecated */ + export const caller: never; + /** @deprecated */ + export const length: never; + /** @deprecated */ + export const name: never; + /** @deprecated */ + export const prototype: never; + /** @deprecated */ + export const toString: never; +} \ No newline at end of file From 29941f695e0eedd85dc36a84bb49ff53888cf36e Mon Sep 17 00:00:00 2001 From: Ottomated Date: Thu, 19 Dec 2024 09:52:18 -0800 Subject: [PATCH 4/6] add helper message for type regeneration --- .github/workflows/ci.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fbdd1e420c82..b2bcb088480b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,7 +59,7 @@ jobs: run: pnpm lint - name: build and check generated types if: (${{ success() }} || ${{ failure() }}) # ensures this step runs even if previous steps fail - run: pnpm build && { [ "`git status --porcelain=v1`" == "" ] || (echo "Generated types have changed — please regenerate types locally and commit the changes after you have reviewed them"; git diff; exit 1); } + run: pnpm build && { [ "`git status --porcelain=v1`" == "" ] || (echo "Generated types have changed — please regenerate types locally with `cd packages/svelte && pnpm generate:types` and commit the changes after you have reviewed them"; git diff; exit 1); } Benchmarks: runs-on: ubuntu-latest timeout-minutes: 15 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a17f49bbeb4b..1daef0b89cc3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,7 +33,7 @@ jobs: run: pnpm install --frozen-lockfile - name: Build - run: pnpm build && { [ "`git status --porcelain=v1`" == "" ] || (echo "Generated types have changed — please regenerate types locally and commit the changes after you have reviewed them"; git diff; exit 1); } + run: pnpm build && { [ "`git status --porcelain=v1`" == "" ] || (echo "Generated types have changed — please regenerate types locally with `cd packages/svelte && pnpm generate:types` and commit the changes after you have reviewed them"; git diff; exit 1); } - name: Create Release Pull Request or Publish to npm id: changesets From 69ab3ee1c50e06647d151e432176b8c5e5f6c52c Mon Sep 17 00:00:00 2001 From: Ottomated Date: Thu, 19 Dec 2024 09:52:25 -0800 Subject: [PATCH 5/6] append a newline to generated types --- packages/svelte/scripts/generate-types.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/svelte/scripts/generate-types.js b/packages/svelte/scripts/generate-types.js index 16bbf52a2e07..d44afe8205a8 100644 --- a/packages/svelte/scripts/generate-types.js +++ b/packages/svelte/scripts/generate-types.js @@ -46,6 +46,8 @@ await createBundle({ } }); +fs.appendFileSync(`${dir}/types/index.d.ts`, '\n'); + const types = fs.readFileSync(`${dir}/types/index.d.ts`, 'utf-8'); const bad_links = [...types.matchAll(/\]\((\/[^)]+)\)/g)]; From 8d857320157ef5c0c7163e8a3ec80e72d52ce6f9 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 19 Dec 2024 13:05:24 -0500 Subject: [PATCH 6/6] prettier --- packages/svelte/src/ambient.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/svelte/src/ambient.d.ts b/packages/svelte/src/ambient.d.ts index bb2a83810899..9dbc61c7cbd4 100644 --- a/packages/svelte/src/ambient.d.ts +++ b/packages/svelte/src/ambient.d.ts @@ -499,4 +499,4 @@ declare namespace $host { export const prototype: never; /** @deprecated */ export const toString: never; -} \ No newline at end of file +}