microsoft / microsoft/TypeScript
Intellisense: optional parameters are too verbose (bar? number | undefined)
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
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>
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza rastreando la visualización de firmas de TypeScript IntelliSense para parámetros opcionales y comparando los ejemplos del issue con la salida actual. Se considera completado cuando los parámetros y las propiedades opcionales ya no muestran redundantemente | undefined cuando el signo de interrogación ya transmite esa información, mientras los demás detalles de la firma siguen siendo visibles.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers, developer-experience
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100