pull/12507/head
Rich Harris 2 years ago
parent 106a4219a9
commit cc1357bfd6

@ -1,25 +1,40 @@
import type { Snippet } from 'svelte'; import type { Snippet } from 'svelte';
const return_type: ReturnType<Snippet> = null as any;
// @ts-expect-error // @ts-expect-error
const a: Snippet<{ text: string }> = () => {}; const a: Snippet<{ text: string }> = () => {};
// @ts-expect-error // @ts-expect-error
const b: Snippet<boolean> = (a, b) => {}; const b: Snippet<boolean> = (a, b) => {
return return_type;
};
// @ts-expect-error
const c: Snippet<boolean> = (a: string) => {
return return_type;
};
// @ts-expect-error // @ts-expect-error
const c: Snippet<boolean> = (a: string) => {}; const d: Snippet<boolean> = (a: string, b: number) => {
return return_type;
};
// @ts-expect-error // @ts-expect-error
const d: Snippet<boolean> = (a: string, b: number) => {}; const e: Snippet = (a: string) => {
return return_type;
};
// @ts-expect-error // @ts-expect-error
const e: Snippet = (a: string) => {};
const f: Snippet = (a) => { const f: Snippet = (a) => {
// @ts-expect-error
a?.x; a?.x;
return return_type;
}; };
const g: Snippet<[boolean]> = (internals, a) => { const g: Snippet<[boolean]> = (a) => {
// @ts-expect-error // @ts-expect-error
a() === ''; a === '';
a() === true; a === true;
return return_type;
};
const h: Snippet<[{ a: true }]> = (a) => {
a.a === true;
return return_type;
}; };
const h: Snippet<[{ a: true }]> = (internals, a) => { const i: Snippet = () => {
a().a === true; return return_type;
}; };
const i: Snippet = () => {};

@ -261,10 +261,7 @@ declare module 'svelte' {
element?: typeof HTMLElement; element?: typeof HTMLElement;
}; };
/** const SnippetReturn: unique symbol;
* Internal implementation details that vary between environments
*/
export type SnippetInternals = Branded<{}, 'SnippetInternals'>;
// Use an interface instead of a type, makes for better intellisense info because the type is named in more situations. // Use an interface instead of a type, makes for better intellisense info because the type is named in more situations.
/** /**
@ -281,12 +278,13 @@ declare module 'svelte' {
export interface Snippet<Parameters extends unknown[] = []> { export interface Snippet<Parameters extends unknown[] = []> {
( (
this: void, this: void,
internal: SnippetInternals,
// this conditional allows tuples but not arrays. Arrays would indicate a // this conditional allows tuples but not arrays. Arrays would indicate a
// rest parameter type, which is not supported. If rest parameters are added // rest parameter type, which is not supported. If rest parameters are added
// in the future, the condition can be removed. // in the future, the condition can be removed.
...args: number extends Parameters['length'] ? never : Getters<Parameters> ...args: number extends Parameters['length'] ? never : Parameters
): void; ): typeof SnippetReturn & {
_: 'functions passed to {@render ...} tags must use the `Snippet` type imported from "svelte"';
};
} }
interface DispatchOptions { interface DispatchOptions {

Loading…
Cancel
Save