Skip to content

Commit d6d1ff4

Browse files
committed
add missing file
1 parent 2e46823 commit d6d1ff4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

typescript/src/utilTypes.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ConditionalPick } from 'type-fest'
2+
3+
type Tail<T> = T extends readonly [...any[], infer U] ? U : never
4+
type GetIs<T> = T extends (elem: any) => elem is infer T ? T : never
5+
6+
type TSNodeIs = ConditionalPick<typeof ts, (node: ts.Node) => node is ts.Node>
7+
type Comparisons = {
8+
[T in keyof TSNodeIs as T extends `is${infer U}` ? /* Uncapitalize<U> */ U : never]: GetIs<(typeof ts)[T & keyof typeof ts]>
9+
}
10+
11+
export type MatchParentsType = <K extends keyof Comparisons, const T extends readonly [...K[]]>(
12+
node: ts.Node | undefined,
13+
treeToCompare: T,
14+
) => Comparisons[Tail<T> & keyof Comparisons] | undefined

0 commit comments

Comments
 (0)