Readme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Statement } from "https://esm.town/v/postpostscript/sqliteBuilder";
// this is apparently a dubious solution (https://github.com/microsoft/TypeScript/issues/13298#issuecomment-468375328),
// but this seems to work: https://github.com/microsoft/TypeScript/issues/13298#issuecomment-885980381
type UnionToIntersection<U> = (
U extends never ? never : (arg: U) => never
) extends (arg: infer I) => void ? I
: never;
type UnionToTuple<T> = UnionToIntersection<
T extends never ? never : (t: T) => T
> extends (_: never) => infer W ? [...UnionToTuple<Exclude<T, W>>, W]
: [];
// ---
type EntryTuple<T> = UnionToTuple<
{
[K in keyof T]: [K, T[K]];
}[keyof T]
>;
type KeyTuple<T> = EntryTuple<T> extends infer E ? {
[Index in keyof E]: E[Index] extends [infer K, any] ? K
: never;
}
: never;
type ValueTuple<T> = EntryTuple<T> extends infer E ? {
[Index in keyof E]: E[Index] extends [any, infer V] ? V
: never;
}
: never;
export function StatementTyped<T>(
strings: TemplateStringsArray,
// @ts-ignore
...replacements: ValueTuple<T>
) {
// @ts-ignore
return Statement(strings, ...replacements);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.