microsoft / microsoft/TypeScript

Extend createMethodSignature and updateMethodSignature with 'modifiers' argument

Aperta
#35,959 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: API In Discussion Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia ispezionando le definizioni e le implementazioni della TypeScript Compiler API di createMethodSignature e updateMethodSignature, confrontandole con createPropertySignature e updatePropertySignature. Determina un design non incompatibile per l'argomento modifiers, quindi verifica che le chiamate esistenti rimangano valide e che le firme dei metodi possano essere create o aggiornate con modifiers.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.