microsoft / microsoft/TypeScript
Allow minimal type checking of JavaScript files
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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"],
}
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie damit zu untersuchen, wie Optionen in tsconfig.json wie checkJs, allowJs und strict für JavaScript- und TypeScript-Dateien interpretiert werden. Da im Issue keine Quelldateien, Tests oder Compiler-Einstiegspunkte angegeben sind, verfolgen Sie zunächst die bestehende Behandlung von checkJs und strict. Als erledigt gilt die Aufgabe, wenn JavaScript Fehler aus importiertem typisiertem TypeScript-Code meldet und gleichzeitig nicht zusammengehörige JavaScript-Diagnosen unterdrückt werden, mit Abdeckung für die angeforderte Konfiguration.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100