microsoft / microsoft/TypeScript

Allow `export type Foo;` as valid syntax

Abierto
#30,932 4 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

Search Terms

Exporting a type defined elsewhere. Export a defined type. Type alias circularly references itself. Can't export a type with the same name.

Suggestion

Currently you can only export types right when you declare them:

export type Foo = string | number;

But many people often use ambient files to make their types available globally throughout the project without the need to import them. This however means that the types cannot be exported directly where they define them because the file would cease to be ambient. The current way of coping with this is naming the type differently for internal use and then reexporting it with a different name:

// in types.ts
type _Foo = string | number;

// in index.ts
export type Foo = _Foo;

I suggest that this inconvenience could be easily solved by allowing this syntax:

export type Foo;

Use Cases

As described above, it's useful to export types defined in ambient files.

Examples

As above

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

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

No se nombran archivos, pruebas ni puntos de entrada. Empieza por rastrear cómo TypeScript analiza y comprueba las declaraciones de export type, y determina después los cambios necesarios en el analizador, la comprobación de tipos y las pruebas de regresión; el trabajo estará terminado cuando la sintaxis propuesta se acepte para tipos ambient sin cambiar la salida de JavaScript.

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
Bien especificado
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.