microsoft / microsoft/TypeScript
Allow minimal type checking of JavaScript files
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
I'm in the process of introducing TypeScript support into an enormous, 6-year old web application with a lot of JavaScript files. In order to get the most advantages out of TypeScript while we slowly migrate over (which will likely happen slowly), I'd like the following to be true:
- TypeScript files (
.tsand.tsx) are type checked withstrict: true, so that we get as much useful feedback about TS code as possible. - JavaScript code that imports and then incorrectly uses typed TypeScript code throws a TS error
- Other TypeScript errors in JavaScript files are suppressed, because we haven't had the chance to migrate the file to TypeScript yet. OR, at the least, JavaScript files are type checked with
strict: falseto minimize the number of errors they output.
Primary Suggestion
It would be fantastic if typescript had a "minimalCheckJs" config option that, when set to true, would only check JS files for errors on imported typed code. For example, setting "minimalCheckJs": true, "strict": true in tsconfig.json would have this effect:
# moduleA.ts
function hello(msg) {} # throws "no implicit any" error on "msg" arg
export default function logA(msg: string) {
console.log(msg);
}
# moduleB.js
import logA from './moduleA'
import something from './someJavaScriptFile.js' # does not throw "cannot find module" error
logA(1) # throws TS error, because logA is typed
function logB(msg) { # does not show "no implicit any" error on "msg" arg
console.log(msg);
}
This feature would allow me to convert a file from JS to TS, add types to the file, and immediately be assured that the exported code is being used correctly throughout my entire code base (including JS files). Currently, I can set "checkJs": true, but then I will see thousands of other kinds of errors that TypeScript finds in the JS files, such as cannot find module errors.
Alternative Suggestion
If the above feature is difficult to implement, a less ideal but also helpful feature would be to allow setting "strict": false for JS files and "strict": true for TS files. Some way to combine the following:
# strictly type check TS files
{
"compilerOptions": {
"checkJs": false,
"allowJs": true,
"strict": true
},
"include": ["**/*.ts", "**/*.tsx"],
}
# type check JS files with strict: false
{
"compilerOptions": {
"checkJs": true,
"allowJs": true,
"strict": false
},
"include": ["**/*.js", "**/*.jsx"],
}
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
Comienza examinando cómo se interpretan para archivos JavaScript y TypeScript las opciones de tsconfig.json como checkJs, allowJs y strict. Como en el issue no se identifican archivos fuente, pruebas ni puntos de entrada del compilador, rastrea primero el manejo existente de checkJs y strict. Se considera terminado cuando JavaScript informa de errores procedentes de código TypeScript tipado importado, a la vez que suprime los diagnósticos de JavaScript no relacionados, con cobertura para la configuración solicitada.
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
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100