microsoft / microsoft/TypeScript
Cannot Load Custom Definition File in Repository
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
TypeScript Version: 2.8.1
Search Terms: Definition File, Ambient type
Detail
I am importing a JavaScript library that doesn't have any definition file. I want to create a custom definition file that I place in my repository. I want TypeScript to read this definition file.
I have tried many combination of tsconfig.json (typeRoot, include, path, baseUrl, etc.) Without being successful. I also moved the definition folder under src, and renamed the definition file to index.d.ts (inside a folder with the name of the library) without any success.
Code
Small complete repro here: https://github.com/MrDesjardins/importdefinitionfiles
// main.ts:
import MessageFormat from "messageformat"; // Doesn't have type
// messageformat.d.ts:
declare module messageformat {
export type Msg = (params: {}) => string;
export interface MessageFormat {
new(message: string): any;
compile: (messageSource: string) => Msg;
}
}
Expected behavior: TypeScript to find the definition file and to use it without having a compilation error.
Actual behavior: Error message
Could not find a declaration file for module 'messageformat'. '/Users/pdesjardins/code/perso/importdefinitionfiles/node_modules/messageformat/lib/messageformat.js' implicitly has an 'any' type.
Try `npm install @types/messageformat` if it exists or add a new declaration (.d.ts) file containing `declare module 'messageformat';`
1 import MessageFormat from "messageformat";
Playground Link: https://github.com/MrDesjardins/importdefinitionfiles
Related Issues:
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
Empieza reproduciendo el ejemplo enlazado de importdefinitionfiles con la versión de TypeScript indicada y, después, compara el comportamiento con typescript@next. Lee main.ts, messageformat.d.ts y la configuración de tsconfig.json referenciada mientras sigues el motivo por el que no se encuentra la declaración local. Se considera terminado cuando se descubre la declaración personalizada y el import se compila sin el error de declaración ausente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Activo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100