Skip to content

add ts.createTypeAliasDeclaration #15489

Closed

Description

@mohsen1

TypeScript Version: 2.3.2
Code

type Foo = {}

How can I generate a node that is equivalent of above source code?

Activity

  1. mhegazy commented on May 1, 2017

    @mhegazy
    Contributor

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

  2. mhegazy commented on May 1, 2017

    @mhegazy
    Contributor

    PRs welcomed.

  3. mohsen1 commented on May 1, 2017

    @mohsen1
    ContributorAuthor

    Also need to add {create|update}InterfaceDeclaration

  4. mohsen1 commented on May 1, 2017

    @mohsen1
    ContributorAuthor

    I came up with this hack for now:

    function buildTypeDeclarationStatement(name: string, type: ts.TypeNode, sourceFile: ts.SourceFile) {
        const printer = ts.createPrinter()
        const typeString = printer.printNode(ts.EmitHint.Unspecified, type, sourceFile);
        const newSource = ts.createSourceFile('temp.ts', `type ${name} = ${typeString}`, sourceFile.languageVersion);
        return newSource.statements[0];
    }
  5. mhegazy commented on May 1, 2017

    @mhegazy
    Contributor

    yup, #15497

  6. changed the title [-]How to create a TypeAliasDeclaration?[/-] [+]add ts.createTypeAliasDeclaration[/+] on May 1, 2017
  7. 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