-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] add convenience types ComponentType and ComponentProps (#6770)
ComponentType eases typing "this is a variable that expects a Svelte component constructor (of a certain shape)". Removes the need for SvelteComponentTyped to be an extra type so it can be deprecated in v4 and removed in v5, and SvelteComponent(Dev) can receive the same generic typings as SvelteComponetTyped in v4. ComponentProps eases typing "give me the props this component expects". Closes #7584 Co-authored-by: Simon Holthausen <simon.holthausen@accso.de> Co-authored-by: Hofer Ivan <ivan.hofer@outlook.com> Co-authored-by: Ignatius Bagus <ignatius.mbs@gmail.com>
- Loading branch information
1 parent
2f562d9
commit 6f57571
Showing
6 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// This script generates the TypeScript definitions | ||
|
||
const { execSync } = require('child_process'); | ||
const { readFileSync, writeFileSync } = require('fs'); | ||
|
||
execSync('tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emitDeclarationOnly'); | ||
|
||
// We need to add these types to the index.d.ts here because if we add them before building, the build will fail, | ||
// because the TS->JS transformation doesn't know these exports are types and produces code that fails at runtime. | ||
// We can't use `export type` syntax either because the TS version we're on doesn't have this feature yet. | ||
const path = 'types/runtime/index.d.ts'; | ||
const content = readFileSync(path, 'utf8'); | ||
writeFileSync(path, content.replace('SvelteComponentTyped', 'SvelteComponentTyped, ComponentType, ComponentConstructorOptions, ComponentProps')); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters