-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler API: Creating a TypeNode from a string? #23042
Comments
TypeNode
from a string?
I usually create a string with a variable declaration with the type I want to parse and parse it as a SourceFile: ts.createSourceFile('tmp.ts', `let a:${type}`).statements[0].declarationList.declarations[0].type; |
Is there a cleaner way to do it? I think that feels pretty dirty. |
@ajafff your solution also produces an unexpected result when emitted.
Note how the "key" name is lost. How come? Any way to get around this? |
When emitting a transformed file, you always need to pass the original SourceFile object. This is then used to look up the content of not modified nodes. |
Seems related to #9883 |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
In TypeScript, how can I turn the string
{ [index: string]: { foo: string } }
into aTypeNode
in the compiler API? Is that possible?I already tried doing this by creating a "file" and putting the contents into it and parsing it, but that doesn't seem to be creating a
TypeNode
.Any ideas?
The text was updated successfully, but these errors were encountered: