microsoft / microsoft/TypeScript

json files should be usable in .d.ts files without breaking things

Abierto
#24,744 9 comentarios 5 reacciones 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
1 d 19 h
PR fusionados (30 d)
117

Descripción

Search Terms

resolveJsonModule import definition

Suggestion

As a .json file is a static resource, it should be able to be referenced in a global.d.ts file for example without that file being automatically treated as a module. The reason for this is that a .json file may be used to simply enforce valid translation keys, and you shouldn't need to suck the whole .json file into the transpilation process to do that.

Use Cases

Example:

import translations from "../assets/translations/en-AU.json"
type $translate = {
    instant: (translationKey: keyof typeof translations) => string,
    use: Function,
    proposedLanguage: Function
}

The downside of the current method again is that the translations file is output in the transpilation process, which is wasteful if the file is large.

What the above code snippet is trying to achieve, should be allowed in a .d.ts file without breaking global declaration functionality.

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. new expression-level syntax)

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

Comienza reproduciendo el ejemplo que involucra global.d.ts, un archivo .d.ts y ../assets/translations/en-AU.json; después, inspecciona cómo se gestionan actualmente los archivos de declaración y las importaciones de JSON. La tarea estará terminada cuando el ejemplo pueda hacer referencia al JSON para las claves de traducción sin romper las declaraciones globales ni incluir innecesariamente el JSON en la salida de transpilación.

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
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.