Skip to content

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

Closed

Description

@phated

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.

Activity

  1. mhegazy commented on May 1, 2017

    @mhegazy
    Contributor

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

  2. mhegazy commented on May 1, 2017

    @mhegazy
    Contributor

    PRs welcomed.

  3. phated commented on May 1, 2017

    @phated
    ContributorAuthor

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

  4. mhegazy commented on May 1, 2017

    @mhegazy
    Contributor

    No.

  5. added a commit that references this issue on May 1, 2017
    b39a2a7
  6. mohsen1 commented on May 1, 2017

    @mohsen1
    Contributor

    Blaine Bublitz (@phated) can you also fix #15489 in your PR?

  7. phated commented on May 1, 2017

    @phated
    ContributorAuthor

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

  8. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions