mirror of https://github.com/sveltejs/svelte
[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>pull/7662/head
parent
2f562d9e28
commit
6f57571507
@ -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'));
|
Loading…
Reference in new issue