Skip to content

Instantly share code, notes, and snippets.

@dsherret
Created November 27, 2018 05:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsherret/0a54d081cdd86a178c979ef73563e5cc to your computer and use it in GitHub Desktop.
Save dsherret/0a54d081cdd86a178c979ef73563e5cc to your computer and use it in GitHub Desktop.
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