Skip to content

Instantly share code, notes, and snippets.

@mattiamanzati
Created March 10, 2018 09:35
Show Gist options
  • Save mattiamanzati/767bc0214ba1061510f44948e35f4efd to your computer and use it in GitHub Desktop.
Save mattiamanzati/767bc0214ba1061510f44948e35f4efd to your computer and use it in GitHub Desktop.
import { TaskEither } from "fp-ts/lib/TaskEither";
import * as ts from "typescript";
type SyntaxKindToValueType = {
[ts.SyntaxKind.StringLiteral]: string;
[ts.SyntaxKind.NumericLiteral]: number;
};
type NumericStringToNumer<N extends string> = ({
"8": 8
"9": 9;
} & { [K: string]: never })[N];
type NumerToNumericString<N extends number> = ({
8: "8",
9:"9"
} & { [K: number]: never })[N];
type SupportedNodes = { kind: keyof SyntaxKindToValueType };
type IExecutionContext = {};
declare function compileNode<K extends NumericStringToNumer<keyof SyntaxKindToValueType>>(
node: { kind: K } & ts.Node
): (x: IExecutionContext) => TaskEither<never, SyntaxKindToValueType[NumerToNumericString<K>]>;
const shouldBeString = compileNode((1 as any) as ts.StringLiteral);
const shouldBeNumber = compileNode((1 as any) as ts.NumericLiteral);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment