microsoft / microsoft/TypeScript
Clean up syntax for importing and using nested type declarations
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
Search Terms
- import
- import equals
- nested import
Suggestion
The current syntax for importing nested modules is confusing. For example, to specifically use a single property from an interface I would need to do something like this:
// interface.ts
interface Example {
Foo: string
}
// file.ts
import { Example } from 'interface.ts';
import Foo = Example.Foo // this is weird, as I'm not actually importing any resource here
From what I understand, import is not importing anything here. It's confusing and looks like it's doing something totally different at first glance. In this case, I could also use type Bind = interfaces.Bind, but I don't want to create a new resource.
A much nicer syntax would be adding a use or take keyword, or adding support for importing nested modules
Use Cases
This suggestion is just for readability and developer experience.
Examples
Importing nested modules with use or take
// interface.ts
interface Example {
Foo: string
}
// file.ts
import { Example } from 'interface.ts';
take { Foo } from Example;
importing nested interface/namespace values:
// interface.ts
interface Example {
Foo: string
}
// file.ts
import { Example: { Foo } } from 'interface.ts';
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
Revisa los ejemplos de declaraciones anidadas en interface.ts y file.ts, incluida la forma import-equals existente y las formas propuestas use, take y nested-import. Determina la sintaxis prevista y el comportamiento de la comprobación de tipos antes de considerar la implementación; para darlo por terminado se requerirían un diseño acordado y pruebas del compilador y de regresión, y en el issue no se identifica ninguno de ellos.
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
- Necesita aclaración
- Aptitud para principiantes
- 25/100