Skip to content

Commit

Permalink
syntax/types: Derive ChildKeyByNodeType type from visitorKeys obj…
Browse files Browse the repository at this point in the history
…ect definition
  • Loading branch information
Turbo87 committed Dec 24, 2018
1 parent ebe2ef1 commit 15f3633
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/@glimmer/syntax/lib/types/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VisitorKeysMap } from './visitor-keys';
import visitorKeys, { VisitorKeysMap } from './visitor-keys';

export type Option<T> = T | null;

Expand Down Expand Up @@ -212,8 +212,7 @@ export type NodeType = keyof Nodes;
export type Node = Nodes[NodeType];

// VisitorKeysMap drives ParentNode and LeafNode typing
export type ValuesOfType<T, U> = { [K in keyof T]: T[K] extends U ? T[K] : never }[keyof T];
export type ChildKeyByNodeType = { [T in NodeType]: ValuesOfType<VisitorKeysMap[T], string> };
export type ChildKeyByNodeType = { [T in keyof VisitorKeysMap]: typeof visitorKeys[T][number] };

// All potential child keys, e.g. `body`, `value`, `path`, ...
export type ChildKey = ChildKeyByNodeType[NodeType];
Expand Down

0 comments on commit 15f3633

Please sign in to comment.