Skip to content

(auto-) generate a typescript d.ts file for better IDE Support #106

Closed
@jamestalmage

Description

@jamestalmage

Since basically every interesting method of this library is dynamically generated, it's impossible for IDE's like WebStorm to provide much help with autocompletion and/or static type analysis. I don't want to know how many hours I have lost context switching between my code and def/*, trying to figure out what the correct signature was for various build methods.

I created a minimal one by hand (currently only supports Identifier, ReturnStatement, and AssignmentExpression).

Note that it's utility would not be limited to Typescript users. IDE's can use them to provide hints for plain old javascript code as well. All the screenshots below are actually code hints generated for a javascript file.

Code Completion
screenshot 2015-04-10 16 51 50

Type Checking
screenshot 2015-04-10 16 26 28

Method Signature Hints
screenshot 2015-04-10 16 43 42

Webstorm just knows the type of the assign variable.
screenshot 2015-04-10 16 18 24

Everything we need to auto-generate the definition file is already in def/*, but we would probably need to extend Type to expose the information it contains in a format readily consumed by the generator (I guess I could parse Types toString output, but that seems unnecessarily difficult).

The generated file for the default language definitions shipped with ast-types should probably be deployed into npm as a static asset, but it would also be possible to generate it via a postinstall script. Ideally we would provide programmatic access as well, so those extending the language definitions (i.e. #57) could create their own definition files that reflect their modifications.

I am happy to submit a PR if @benjamn is on board. I am not sure how close #57 is to being a reality, but it would be nice to see what direction you were taking with that before starting on this in earnest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions