GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Add support to report errors in js files by mhegazy · Pull Request #14496 · microsoft/TypeScript Conversation
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This means that it'll be possible to opt-in to have types that can be inferred from the environment ( Sounds pretty great for progressively migrating a codebase to typescript 🎉 I wonder how this interacts with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
correct. this is the intention.
I do not know what is the best solution here. We were discussing this topic today, and we are doing some additional inferences/modifications to types in a .js file that we do not do in a .ts file. some of these involve |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,6 @@ | |||
| // @allowJs: true | |||
| // @checkJsFiles: true | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You might want to add @noEmit: true or @outFile to suppress all the Cannot write file... because it would overwrite errors in the baselines.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| }, | ||
| { | ||
| name: "checkJsFiles", |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Since we have allowJs, shouldn't this be checkJs? Having 'Files' on just one of them seems inconsistent.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Instead, we'll report errors for using TypeScript-only constructs from within a | ||
| // JavaScript file when we get syntactic diagnostics for the file. | ||
| const checkDiagnostics = isSourceFileJavaScript(sourceFile) ? [] : typeChecker.getDiagnostics(sourceFile, cancellationToken); | ||
| // For JavaScript files, we don't want to report semantic errors unless ecplicitlly requested. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Spelling
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| } | ||
|
|
||
| const checkJsDirectiveRegEx = /^\/\/\/?\s*@check(\s+(true|false))?/gim; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Or maybe an nocheck directive?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…' into checkJSFiles_QuickFixes
Allow skipping diagnostics in .js file using comments and quick fixes to add them
| function shouldReportDiagnostic(diagnostic: Diagnostic) { | ||
| const { file, start } = diagnostic; | ||
| const lineStarts = getLineStarts(file); | ||
| let { line } = computeLineAndCharacterOfPosition(lineStarts, start); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
ts-suppress should be located immediately before the line to be suppressed so if user will put a comment between ts-suppress and target line it will stop working. Is it intended?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| .map(d => allDiagnostcs[d].code); | ||
| } | ||
|
|
||
| function shouldCheckJsFile(sourceFile: SourceFile, compilerOptions: CompilerOptions) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
this is the same snipped with this one. Can we share this?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
| } | ||
|
|
||
| const checkJsDirectiveRegEx = /^\/\/\/?\s*(@ts-check|@ts-nocheck)\s*$/gim; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would recommend you pull this out of the function and remove the g option. g is only really useful if you want to preserve lastIndex when using a regular expression in a loop. Also I would remove the m option as it should be unnecessary.
Consider this instead:
const checkJsDirectiveRegEx = /^\/\/\/?\s*@ts-(no)?check\s*$/i; ... const checkJsDirectiveMatchResult = checkJsDirectiveRegEx.exec(comment); if (checkJsDirectiveMatchResult) { checkJsDirective = { enabled: !!checkJsDirectiveMatchResult[1], end: range.end, pos: range.pos }; }
Capturing only the no allows you to avoid the additional case-insensitive string comparison.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Does this close #7661 ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Nope. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Very nice option. But it will be more powerful if allows to suppression several errors |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.