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

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

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

Loading…
Cancel
Save