You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today, I have learned about some new (~1-2 year old) compiler options of TypeScript which help to write better code and prevent errors. That is why I suggest that we implement this flag (called strict mode) in this library and also in all Angular/TypeScript projects that we have.
From the documentation:
Enable all strict type checking options.
Enabling --strict enables --noImplicitAny, --noImplicitThis, --alwaysStrict, --strictBindCallApply, --strictNullChecks, --strictFunctionTypes and --strictPropertyInitialization.
To summarize: The compiler option strict enables seven flags that help you write better code. It is possible that in future releases more flags will be added.
As of now, we only have two flags set in this library: noImplicitAny and strictNullChecks. I suggest we remove those two flags from tsconfig.json and replace it with strict: true.
The text was updated successfully, but these errors were encountered:
The strict flag forbids you to do things like that:
export class User {
name: string;
}
Then:
const user = new User();
console.log(user.name); // undefined even though we told the compiler it should be string
I have dicussed implications of this issue with @tobiasschweizer on the phone lately. Basically, as of now, you can define such a User class which never assigns a name. It basically means that name can be undefined and it should be flagged as such.
With the strict flags, developers are forced to write name: string | undefined or assign a value in the constructor.
Yes, but strict is a superset of that and thus better. Microsoft/Typescript states that in future they may add more flags that will be still covered if strict is set to true.
Today, I have learned about some new (~1-2 year old) compiler options of TypeScript which help to write better code and prevent errors. That is why I suggest that we implement this flag (called
strict
mode) in this library and also in all Angular/TypeScript projects that we have.From the documentation:
Source: https://www.typescriptlang.org/docs/handbook/compiler-options.html
To summarize: The compiler option
strict
enables seven flags that help you write better code. It is possible that in future releases more flags will be added.As of now, we only have two flags set in this library:
noImplicitAny
andstrictNullChecks
. I suggest we remove those two flags fromtsconfig.json
and replace it withstrict: true
.The text was updated successfully, but these errors were encountered: