Created
November 27, 2018 05:17
-
-
Save dsherret/0a54d081cdd86a178c979ef73563e5cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Project } from "ts-simple-ast"; | |
const project = new Project({ useVirtualFileSystem: true }); | |
const sourceFile = project.createSourceFile("test.ts", `type ToString<T> = "1";\ntype Result = ToString<1>;`); | |
const toStringTypeAlias = sourceFile.getTypeAliasOrThrow("ToString"); | |
const resultTypeAlias = sourceFile.getTypeAliasOrThrow("Result"); | |
let i = 2; | |
while (true) { | |
const toStringTypeNode = toStringTypeAlias.getTypeNodeOrThrow(); | |
toStringTypeNode.replaceWithText(writer => | |
writer.writeLine(`T extends ${i} ? "${i}" :`).indent().write(toStringTypeNode.getText())); | |
if (resultTypeAlias.getType().getText(resultTypeAlias) !== `"1"`) { | |
console.log(sourceFile.getFullText()); | |
throw "STOP"; | |
} | |
i++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment