GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — New --strict master option by ahejlsberg · Pull Request #14486 · microsoft/TypeScript

Conversation

@ahejlsberg

@ahejlsberg Anders Hejlsberg (ahejlsberg) commented Mar 6, 2017

Copy link
Copy Markdown
Member

This PR introduces a new --strict compiler option that represents the recommended setting of a number of type checking options. Specifically, specifying --strict corresponds to specifying all of the following options (and may in the future include more options):

  • --strictNullChecks
  • --noImplicitAny
  • --noImplicitThis
  • --alwaysStrict

When we introduce new type checker features in TypeScript we often put them under a compiler switch and leave them off by default in order to avoid breaking existing projects. While avoiding breakage is a good thing, this strategy has the drawback of making it increasingly complex to choose the highest level of type safety, and doing so requires explicit opt-in action on every TypeScript release. With the --strict option it becomes possible to choose maximum type safety with the understanding that additional errors might be reported by newer versions of the compiler as improved type checking features are added.

In exact terms, the --strict option sets the default value for the compiler options listed above. This means it is still possible to individually control the options. For example,

--strict --noImplicitThis false

has the effect of turning on all strict options except the --noImplicitThis option. Using this scheme it is possible to express configurations consisting of all strict options except some explicitly listed options. In other words, it is now possible to default to the highest level of type safety but opt out of certain checks.

The PR also modifies the default tsconfig.json generated by tsc --init to include a "strict": true setting in the "compilerOptions" section. Thus, new projects started with tsc --init will by default have the highest level of type safety enabled.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

basarat, peterkelly, rkirov, alexeagle, brsanthu, s5no5t, spion, mariusschulz, eduacostam, NikitaRzm, and 15 more reacted with thumbs up emoji sivabudh, arodik, AlexKhymenko, and imhoffd reacted with laugh emoji Jessidhia, SlurpTheo, patrick91, antanas-arvasevicius, abenhamdine, AlexeyMz, basarat, use-strict, mariusschulz, piotrwitek, and 2 more reacted with hooray emoji DanielRosenwasser, quanterion, tinganho, Jessidhia, Zalastax, dsherret, joews, mkusher, basarat, mpawelski, and 13 more reacted with heart emoji
All reactions
  • 👍 25 reactions
  • 😄 4 reactions
  • 🎉 12 reactions
  • ❤️ 23 reactions
Anders Hejlsberg (ahejlsberg) added 3 commits March 3, 2017 10:25
@ahejlsberg
Introduce --strict compiler option
cda741d
@ahejlsberg
Merge branch 'master' into strictChecks
a4e80b5
@ahejlsberg
Accept new tsconfig baselines
7ed13d0
@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-not-required label Mar 6, 2017
DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) requested changes Mar 6, 2017
View reviewed changes
Comment thread src/compiler/checker.ts
return undefined;
}
else if (compilerOptions.noImplicitAny && moduleNotFoundError) {
else if (noImplicitAny && moduleNotFoundError) {

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Mar 6, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This sort of thing is a bug waiting to happen - it is very likely that next time someone will need to check a flag like noImplicitAny, they will go through compilerOptions first. That said, I'm not sure what else we could do here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/compiler/commandLineParser.ts Outdated
module: ModuleKind.CommonJS,
target: ScriptTarget.ES5,
noImplicitAny: false,
strict: false,

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Mar 6, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The PR also modifies the default tsconfig.json generated by tsc --init to include a "strict": true setting in the "compilerOptions" section. Thus, new projects started with tsc --init will by default have the highest level of type safety enabled.

Doesn't look like this is an accurate statement.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ahejlsberg Anders Hejlsberg (ahejlsberg) Mar 6, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Fixed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mhegazy
Mohamed Hegazy (mhegazy) approved these changes Mar 6, 2017
View reviewed changes

@mhegazy Mohamed Hegazy (mhegazy) left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

👍 with chaining the default of --init to true.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Anders Hejlsberg (ahejlsberg) added 2 commits March 6, 2017 13:04
@ahejlsberg
Change 'tsc --init' to default to 'strict: true'
d3b7058
@ahejlsberg
Accept new baselines
de120b3
@ahejlsberg
Anders Hejlsberg (ahejlsberg) merged commit f7242f3 into master Mar 6, 2017
@ahejlsberg
Anders Hejlsberg (ahejlsberg) deleted the strictChecks branch March 6, 2017 21:23
@jods4 jods (jods4) mentioned this pull request Mar 6, 2017
Default compiler options #9642
Closed
@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request Mar 7, 2017
Design Meeting Notes, 3/3/2017 #14440
Closed
@kitsonk Kitson Kelly (kitsonk) mentioned this pull request Mar 9, 2017
Migration to TypeScript 2.3 dojo/meta#153
Closed
@joews Joe Whitfield-Seed (joews) mentioned this pull request Mar 12, 2017
Typescript strict mode joews/peach#37
Merged
4 tasks done
@zaggino

Martin Zagora (zaggino) commented Apr 26, 2017

Copy link
Copy Markdown

Question, why isn't noImplicitReturns part of the strict mode? or others - noUnusedLocals, noFallthroughCasesInSwitch seem also like something I'd expect in strict mode

buu700 and tiktuk reacted with thumbs up emoji SlurpTheo reacted with thumbs down emoji
All reactions
  • 👍 2 reactions
  • 👎 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Apr 27, 2017

Copy link
Copy Markdown
Contributor

Question, why isn't noImplicitReturns part of the strict mode? or others - noUnusedLocals, noFallthroughCasesInSwitch seem also like something I'd expect in strict mode

We had a discussion about this, and these checks along with --noUnusedLocals and --noUnusedParameters seemed "style" options and not "type checking" options. that is why the flag description stresses the "type checks" part.

SlurpTheo and buu700 reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@buu700

Ryan Lester (buu700) commented Apr 27, 2017

Copy link
Copy Markdown

Do you think it's worth putting all the flags that fit in with the group Martin Zagora (@zaggino) mentioned in a separate flag ("strictStyle", or whatever makes sense to call it) or as an optional argument to the strict flag?

The reasoning makes sense to me, but I was surprised to see in today's release notes that those weren't all included; this flag would have been much more useful to me if it did include all that and I could use it as a way to automatically track every strictness-related compiler option going forward.

zaggino and SlurpTheo reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Apr 27, 2017

Copy link
Copy Markdown
Contributor

I do ont think so. style checks are by definition subjective. so not every one would agree on the value of enabling one of them. for example the TS code base heavily relies on implicit returns, and fallthroughs, we do not see these as problems.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@styfle

Steven (styfle) commented Oct 26, 2017

Copy link
Copy Markdown
Contributor

Is there a Visual Studio compiler flag for --strict?
I found msbuild options but it doesn't mention the --strict option.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Oct 26, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
<TypeScriptStrict>true</TypeScriptStrict>
styfle reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Steven (styfle) added a commit to styfle/TypeScript-Handbook that referenced this pull request Oct 27, 2017
@styfle
Add --strict compiler option in msbuild
4a9d8fb
The `--strict` flag was added in microsoft/TypeScript#14486
@styfle Steven (styfle) mentioned this pull request Oct 27, 2017
Add --strict compiler option in msbuild microsoft/TypeScript-Handbook#676
Merged
@ahejlsberg Anders Hejlsberg (ahejlsberg) mentioned this pull request Dec 17, 2017
Several issues with strict property checks and definite assignement assertion #20740
Closed
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) DanielRosenwasser requested changes
+1 more reviewer
@mhegazy Mohamed Hegazy (mhegazy) mhegazy approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@ahejlsberg @zaggino @mhegazy @buu700 @styfle @DanielRosenwasser @msftclas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.