microsoft / microsoft/TypeScript

Intellisense: optional parameters are too verbose (bar? number | undefined)

Aperta
#32,282 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

Search Terms

optional parameters intellisense

Suggestion

The intellisense for optional parameters is too verbose:

an optional function parameter defined e.g. like this

function foo (bar?: number) {
}

gets resolved in the intellisense as

function foo(bar?: number | undefined): void

The optional nature of the bar parameter is indicated two times, once with number | undefined type and once with the question mark sign bar?:

Proposal:

Just use question mark in intellisense signatures

function foo(bar?: number): void

Use Cases

The | undefined bloats the length of the function signatures generated by the intellisense. This
makes the signatures too long leading to loss of important information in the intellisense in longer methods (e.g. the return types are shortened...)

Examples

Here is an example:

class IotFileClient {
public async GetFiles(
        entityid: string,
        params?: { 
            offset?: number; 
            limit?: number; 
            count?: boolean; 
            order?: string; 
            filter?: string; 
            }
    ): Promise<IotFileModels.IFile> {
         return {name: "test"};
    }
}

This produces the intellisense output like this:

(method) IotFileClient.GetFiles(entityid: string, params?: {
    offset?: number | undefined;
    limit?: number | undefined;
    count?: boolean | undefined;
    order?: string | undefined;
    filter?: string | undefined;
} | undefined): Promise<...>

Using only ?: would reduce the verbosity and leave much more room for the important information e.g. for the return values:

(method) IotFileClient.GetFiles(entityid: string, params?: {
    offset?: number;
    limit?: number;
    count?: boolean;
    order?: string;
    filter?: string;
}): Promise<IotFileModels.IFile>

http://www.typescriptlang.org/play/#code/KYDwDg9gTgLgBAOwIYFtgGcxIMbDgSQhgDEBLAG2AFkIATYc9OAbwCg4O5RJY5SEYwKADMcefGUot2nWcjQAuOOhhR+AcwDcMjgF9W+1tnJJ0TQiQrAAwuVLAB0sAFcARnexxTATwSeA4sCWlOgAFDqyXAKkMN6ktEoqagjqADQRslhQqOgA-ErMcBmRHBDCwuhB+YjOKK5CmkUlJXYoMdUItfVQjcUl2BDOAtWuEBCUSAi9zZHQ9FDVSRrTM5zCFIILCksp2quc+rIAlEoAClAQbZUAPBaS1HQM6AB0ElYAfNKrUEHOUAgseTAJQAIkEKhBuj2BwMrFYwiG2BgpAgAOEYzgoVcSC2NTqQiOXyKuiAA

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 tracciando la visualizzazione della firma di TypeScript IntelliSense per i parametri opzionali e confrontando gli esempi dell’issue con l’output attuale. Il lavoro è completato quando i parametri e le proprietà opzionali non mostrano più in modo ridondante | undefined quando il punto interrogativo trasmette già quell’informazione, mentre gli altri dettagli della firma rimangono visibili.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers, developer-experience
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 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.