Checkjs implies allowjs by sandersn · Pull Request #40275 · microsoft/TypeScript (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation9 Commits5 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

sandersn

If it's not explicitly provided.

Note that it's still an error to explicitly provide checkJs: true, allowJs: false.

This change makes the compiler options easier to use and to describe.

@sandersn

Even if you have "allowJs": false. This is not a useful combination.

Changing this makes the compiler more friendly and easier to describe.

@sandersn

@sandersn

@sandersn

@sandersn

@weswigham

For other defaulted flags dependent on other flags, we have something like a getStrictCompilerOptionValue helper that we use everywhere rather than checking the compiler options directly (no, I don't think createProgram handles all inputs - transpileModule is notable for probably being unaffected). You should probably add a getAllowJSCompilerOption helper that we use everywhere rather than checking the flags directly.

@sandersn

@sandersn

I thought that might be the case. I switched to an accessor function getAllowJSCompilerOption instead.

weswigham

sheetalkamat

@@ -3160,7 +3160,7 @@ namespace ts {
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_when_option_target_is_ES3, "useDefineForClassFields");
}
if (options.checkJs && !options.allowJs) {
if (options.checkJs && !getAllowJSCompilerOption(options)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems incorrect condition. You want to check if options.allowJs === false here instead

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duh, thanks for the catch.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, wait, that undoes the loosening from this PR. THe current code only errors when checkJs: true but allowJs: false explicitly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (options.checkJs && !getAllowJSCompilerOption(options)) {
if (options.checkJs && options.allowJs === false) {

will also work and won’t require a function call.

sheetalkamat

@DanielRosenwasser

I'm not so sure how I feel about this. But I can't think of any reason why it's bad.

@sandersn

Chatted with @RyanCavanaugh, he couldn't either.

He also pointed out that maybe allowJs should default to true now. I'll investigate that next.

@sandersn sandersn deleted the checkjs-implies-allowjs branch

September 1, 2020 17:16