Add tests

This commit is contained in:
Anders Hejlsberg
2024-08-03 11:04:53 -07:00
parent dae40d5f7b
commit c308f58239
3 changed files with 347 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
// @strict: true
// @noemit: true
// https://github.com/microsoft/TypeScript/issues/59473
const a: [any] & [1] = [1];
const b: { ml: any } & { ml: 'edge' } = { ml: 'edge' };
// https://github.com/microsoft/TypeScript/issues/48812
type Action<TEvent extends { type: string }> = (ev: TEvent) => void;
interface MachineConfig<TEvent extends { type: string }> {
schema: {
events: TEvent;
};
on?: {
[K in TEvent["type"]]?: Action<TEvent extends { type: K } ? TEvent : never>;
} & {
"*"?: Action<TEvent>;
};
}
declare function createMachine<TEvent extends { type: string }>(
config: MachineConfig<TEvent>
): void;
createMachine({
schema: {
events: {} as { type: "FOO" } | { type: "BAR" },
},
on: {
FOO: (ev) => {
ev.type;
},
},
});
// https://github.com/microsoft/TypeScript/issues/49307#issuecomment-1196014488
type Validate<T> = T & { [K in keyof T]: object }
declare function f<S, T extends Record<string, (state: S) => any>>(s: S, x: Validate<T>): void;
f(0, {
foo: s => s + 1,
})