rename interfcace, rename file, better generic names, never instead of unknown

pull/6770/head
Simon 4 years ago
parent 5902668254
commit 13cc53cdc3

@ -10,4 +10,4 @@ execSync('tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emit
// We can't use `export type` syntax either because the TS version we're on doesn't have this feature yet. // 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 path = 'types/runtime/index.d.ts';
const content = readFileSync(path, 'utf8'); const content = readFileSync(path, 'utf8');
writeFileSync(path, content.replace('SvelteComponentTyped', 'SvelteComponentTyped, ComponentType, ComponentConstructorParams, ComponentProps')); writeFileSync(path, content.replace('SvelteComponentTyped', 'SvelteComponentTyped, ComponentType, ComponentConstructorOptions, ComponentProps'));

@ -95,7 +95,7 @@
"pretest": "npm run build", "pretest": "npm run build",
"posttest": "agadoo internal/index.mjs", "posttest": "agadoo internal/index.mjs",
"prepublishOnly": "node check_publish_env.js && npm run lint && npm test", "prepublishOnly": "node check_publish_env.js && npm run lint && npm test",
"tsd": "node ./tsd.js", "tsd": "node ./generate-type-definitions.js",
"lint": "eslint \"{src,test}/**/*.{ts,js}\"" "lint": "eslint \"{src,test}/**/*.{ts,js}\""
}, },
"repository": { "repository": {

@ -128,7 +128,7 @@ export interface SvelteComponentDev {
$destroy(): void; $destroy(): void;
[accessor: string]: any; [accessor: string]: any;
} }
export interface ComponentConstructorParams<Props extends Record<string, any> = Record<string, any>> { export interface ComponentConstructorOptions<Props extends Record<string, any> = Record<string, any>> {
target: Element | ShadowRoot; target: Element | ShadowRoot;
anchor?: Element; anchor?: Element;
props?: Props; props?: Props;
@ -164,7 +164,7 @@ export class SvelteComponentDev extends SvelteComponent {
*/ */
$$slot_def: any; $$slot_def: any;
constructor(options: ComponentConstructorParams) { constructor(options: ComponentConstructorOptions) {
if (!options || (!options.target && !options.$$inline)) { if (!options || (!options.target && !options.$$inline)) {
throw new Error("'target' is a required option"); throw new Error("'target' is a required option");
} }
@ -256,7 +256,7 @@ export class SvelteComponentTyped<
*/ */
$$slot_def: Slots; $$slot_def: Slots;
constructor(options: ComponentConstructorParams<Props>) { constructor(options: ComponentConstructorOptions<Props>) {
super(options); super(options);
} }
} }
@ -280,8 +280,8 @@ export class SvelteComponentTyped<
* <svelte:element this={componentOfCertainSubType} needsThisProp="hello" /> * <svelte:element this={componentOfCertainSubType} needsThisProp="hello" />
* ``` * ```
*/ */
export type ComponentType<T extends SvelteComponentTyped = SvelteComponentTyped<any, any, any>> = export type ComponentType<Component extends SvelteComponentTyped = SvelteComponentTyped<any, any, any>> =
new (p: ComponentConstructorParams<T extends SvelteComponentTyped<infer X, any, any> ? X : any>) => T; new (p: ComponentConstructorOptions<Component extends SvelteComponentTyped<infer Props, any, any> ? Props : any>) => Component;
/** /**
* Convenience type to get the properties the given component expects. Example: * Convenience type to get the properties the given component expects. Example:
@ -294,9 +294,9 @@ export type ComponentType<T extends SvelteComponentTyped = SvelteComponentTyped<
* </script> * </script>
* ``` * ```
*/ */
export type ComponentProps<T extends SvelteComponent> = T extends SvelteComponentTyped<infer Props> export type ComponentProps<Component extends SvelteComponent> = Component extends SvelteComponentTyped<infer Props>
? Props ? Props
: unknown; : never;
export function loop_guard(timeout) { export function loop_guard(timeout) {
const start = Date.now(); const start = Date.now();

Loading…
Cancel
Save