Skip to content
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

Extend createMethodSignature and updateMethodSignature with 'modifiers' argument #35959

Open
5 tasks done
wessberg opened this issue Jan 2, 2020 · 1 comment
Open
5 tasks done
Labels
API Relates to the public API for TypeScript In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@wessberg
Copy link

wessberg commented Jan 2, 2020

Search Terms

updateMethodSignature, createMethodSignature

Suggestion

It should be possible to provide an array of Modifiers (or undefined) to the createMethodSignature and updateMethodSignature functions.

Use Cases

When using the TypeScript compiler APIs, TypeScript provides numerous create and update functions that can be used to generate an AST, for example from Custom Transformers. However, for MethodSignatures, which may have modifiers such as the static keyword, there's no option to create or update their modifiers. This breaks one of my libraries which sole purpose is to simply deep-clone a TypeScript node. A workaround is to manually patch the modifiers, however I hope this can be part of the function (as it is for others, like createPropertySignature and updatePropertySignature).

Examples

import {createMethodSignature, createNodeArray, createModifier, SyntaxKind} from "typescript";

createMethodSignature(
    createNodeArray([
        createModifier(SyntaxKind.StaticKeyword)
    ]),
    node.typeParameters,
    node.parameters,
    node.type,
    node.name,
    node.questionToken
);

However, the above example would be a breaking change since the first parameter expects a NodeArray of type parameters, so an alternative solution would be to accept it as the last argument.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh RyanCavanaugh added API Relates to the public API for TypeScript In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jan 31, 2020
@wessberg
Copy link
Author

wessberg commented Jul 3, 2020

As part of #35282, I can see that you have added modifiers as the first argument to the new createMethodSignature and updateMethodSignature methods in the NodeFactory interface. Since this is part of the TypeScript v4.0.0, feel free to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants