microsoft / microsoft/TypeScript
Proposal: Allow isolated declarations to infer results of constructor calls
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔍 Search Terms
isolated declarations constructor generic infer
✅ Viability Checklist
- 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, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
Add a new flag or change the behavior of --isolatedDeclarations so that in the following code which is currently disallowed by isolated declarations:
export const foo = new Foo(a);
if the type of foo is not Foo, there is a typecheck error. In return, the type of foo will be emitted as Foo.
Similarly, if somehow in
export const foo: new Foo<A>(a);
foo is not a Foo<A>, there is a typecheck error.
📃 Motivating Example
Currently under isolated declarations, code must redundantly declare the type of a variable which is the result of a constructor call.
export const foo: Foo = new Foo(a);
This setting would also eliminate https://github.com/microsoft/TypeScript/issues/59768
💻 Use Cases
^
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
El issue no menciona archivos, pruebas ni puntos de entrada; empieza rastreando las comprobaciones existentes de --isolatedDeclarations y el comportamiento de inferencia de declaraciones. Se considera completado cuando los resultados de las llamadas a constructores puedan inferirse con la configuración propuesta, y la comprobación de tipos rechace tipos inferidos o anotados que no coincidan sin cambiar el JavaScript emitido.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100