Guest User

Untitled

a guest
Mar 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import { TaskEither } from "fp-ts/lib/TaskEither";
  2. import * as ts from "typescript";
  3.  
  4. type SyntaxKindToValueType = {
  5. [ts.SyntaxKind.StringLiteral]: string;
  6. [ts.SyntaxKind.NumericLiteral]: number;
  7. };
  8.  
  9. type NumericStringToNumer<N extends string> = ({
  10. "8": 8
  11. "9": 9;
  12. } & { [K: string]: never })[N];
  13. type NumerToNumericString<N extends number> = ({
  14. 8: "8",
  15. 9:"9"
  16. } & { [K: number]: never })[N];
  17.  
  18. type SupportedNodes = { kind: keyof SyntaxKindToValueType };
  19.  
  20. type IExecutionContext = {};
  21.  
  22. declare function compileNode<K extends NumericStringToNumer<keyof SyntaxKindToValueType>>(
  23. node: { kind: K } & ts.Node
  24. ): (x: IExecutionContext) => TaskEither<never, SyntaxKindToValueType[NumerToNumericString<K>]>;
  25.  
  26. const shouldBeString = compileNode((1 as any) as ts.StringLiteral);
  27. const shouldBeNumber = compileNode((1 as any) as ts.NumericLiteral);
Add Comment
Please, Sign In to add comment