microsoft / microsoft/TypeScript

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

Offen
#32,282 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

In Discussion Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die TypeScript IntelliSense-Signaturanzeige für optionale Parameter nachzuverfolgen und die Beispiele des Issues mit der aktuellen Ausgabe zu vergleichen. Erledigt ist die Aufgabe, wenn optionale Parameter und Eigenschaften nicht mehr redundant | undefined anzeigen, wenn das Fragezeichen diese Information bereits vermittelt, während andere Signaturdetails sichtbar bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers, developer-experience
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.