Skip to content

Not possible to create an Interface definition in synthetic AST #15497

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

Closed
phated opened this issue May 1, 2017 · 6 comments
Closed

Not possible to create an Interface definition in synthetic AST #15497

phated opened this issue May 1, 2017 · 6 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@phated
Copy link
Contributor

phated commented May 1, 2017

TypeScript Version: 2.3.2

Code

// A *self-contained* demonstration of the problem follows...

// There doesn't seem to be an API to create an Interface in the AST programmatically
const _implementsClause = ts.createHeritageClause(ts.SyntaxKind.ImplementsKeyword, [
    ts.createExpressionWithTypeArguments([], ts.createIdentifier('MyInterface'))
]);
const _exportModifier = ts.createToken(ts.SyntaxKind.ExportKeyword);
const _classExpression = ts.createClassExpression([_exportModifier], 'MyClass', [], [_implementsClause], []);
const _classStatement = ts.createStatement(_classExpression);

let src = ts.createSourceFile('output.ts', '', ts.ScriptTarget.ES5, false, ts.ScriptKind.TS);
src = ts.updateSourceFileNode(src, [_classStatement]);

Expected behavior:
There should be an API for creating an Interface definition in a synthetic AST.

Actual behavior:
Doesn't seem like the API exists.

@mhegazy
Copy link
Contributor

mhegazy commented May 1, 2017

You need to add a createInterfaceDeclaration to factory.ts, something a la createClassDeclaration.

@mhegazy
Copy link
Contributor

mhegazy commented May 1, 2017

PRs welcomed.

@mhegazy mhegazy added Help Wanted You can do this Bug A bug in TypeScript labels May 1, 2017
@mhegazy mhegazy added this to the TypeScript 2.4 milestone May 1, 2017
@phated
Copy link
Contributor Author

phated commented May 1, 2017

@mhegazy will do! One question though: are there tests around these APIs? I couldn't find any.

@mhegazy
Copy link
Contributor

mhegazy commented May 1, 2017

No.

@mohsen1
Copy link
Contributor

mohsen1 commented May 1, 2017

@phated can you also fix #15489 in your PR?

@phated
Copy link
Contributor Author

phated commented May 1, 2017

I'll submit another one for that but I'm tackling some interface stuff right now.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label May 1, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

4 participants