-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.tp
75 lines (60 loc) · 1.61 KB
/
index.tp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
typp TGen<T> = Foo<Names extends T> -> { name: Names }
typp TStr = TGen<string>
// Compiles
type TStr<Names extends string> = { name: Names }
typp T1Or2 = TGen<1 | 2>
// Compiles
type T1Or2<Names extends 1 | 2> = { name: Names }
typp GenericParams = [T extends string, U extends number]
interface Foo<...GenericParams> { name: T, age: U }
// Compiles
interface Foo<T extends string, U extends number> { name: T, age: U }
t(String)
// string
t(Number)
// number
or('1', '2')
// '1' | '2'
or('1', String)
// '1' | (string & {})
and(t({ a: String }), t({ b: Number }))
// { a: string } & { b: number }
const keys = or('oa', 'ob', 'c')
and(keys, t`o${String}`)
// 'oa' | 'ob'
t([ String, Number ])
// [string, number]
t([], String)
// string[]
t([], [], Number)
// number[][]
t({}, String, Number)
// { [x: string]: number }
t({}, String, {}, String, Number)
// { [x: string]: { [x: string]: number } }
t({}, {}, String, Number)
// { [x: PropertyKey]: { [x: string]: number } }
t({ name: String })
// { name: string }
t(Map, String, Number)
// Map<string, number>
t(Set, String)
// Set<string>
t(Promise, String)
// Promise<string>
t(Function, [], String)
// () => string
t(Function, [ String ], Number)
// (a: string) => number
t(Function, [ ], Function, [ String ], Number)
// () => (a: string) => number
t(Function, [ {} ], is(String))
// (a: any) => a is string
t((a = String) => Number)
// (a: string) => number
t((a = {}) => is(String))
// (a: any) => a is string
t((a = generic('T')) => or(a, String))
// <T>(a: T) => T | (string & {})
t((a = generic('T', String)) => or(a, String))
// <T extends string>(a: T) => T | (string & {})