Enable more linter checks in tsconfig.json by default #21279
Comments
|
It is a good idea to consider updating our strictness with recent TypeScript versions. Although it is worth keeping in mind that After discussion within the tooling team, our takeaway with these flags is (interested to get @mgechev's opinion as well):
|
|
Given our null safety target In my opinion, the value I'd be worried to migrate existing projects. The flags for which we can't apply codemods with precise fixes could break many applications without bringing significant value. An optional migration could be a viable option. |
I agree this has less value than something like I could go either way on this one, but I do think catching real typos and mistakes outweighs the desire to use a consistent syntax. If users care that much about syntax, they can always remove the option.
To clarify a bit, I'm not suggesting we migrate existing projects here. I do think it is possible to do a clean migration since |
|
SGTM!
Likewise. We can enable and check people's feedback. Also we can consider if this is a flag enabled in g3 to ensure consistency across the 1P and 3P ecosystems. |
|
Looking internally, it seems that none of these options are currently used. However, there already is a tsetse check which is basically equivalent to I couldn't find an explicit FR for For the other checks, I couldn't find any documented interest in enabling Based on this, my take is that enabling |
…cessFromIndexSignature` to workspace tsconfig With this change, when the workspace is created in strict mode (the default) we add the following additional tsconfig options; - [noImplicitOverride](https://www.typescriptlang.org/tsconfig#noImplicitOverride) - [noPropertyAccessFromIndexSignature](https://www.typescriptlang.org/tsconfig#noPropertyAccessFromIndexSignature) Closes angular#21279
…cessFromIndexSignature` to workspace tsconfig With this change, when the workspace is created in strict mode (the default) we add the following additional tsconfig options; - [noImplicitOverride](https://www.typescriptlang.org/tsconfig#noImplicitOverride) - [noPropertyAccessFromIndexSignature](https://www.typescriptlang.org/tsconfig#noPropertyAccessFromIndexSignature) Closes #21279
|
To anyone interested by this topic: as it's indeed difficult to keep on track of TypeScript best practices, that's why I created Also, while other options may be debatable and a matter of opinion, I also want to backup @dgp1130 about For example: const list: number[] = [1, 2, 3];
if (list.length > 0) {
list[0].toString(); // will report an error saying it could be `undefined`
}It may change in a future release if TypeScript inference gets better, but for now it's indeed an option that should be manually enabled only by people aware of these limitations. |
I think TypeScript actually is powerful enough to infer the type, it just chooses not to because literals are generally inferred as the primitive type ( const list = [1, 2, 3] as const;
list[0].toString(); // worksThe That said, users making this mistake still have to recognize the issue and figure out where to put an |
Command (mark with an
x)Description
Currently, base
tsconfig.jsononly containsstrict,noImplicitReturnsandnoFallthroughCasesInSwitchflagsDescribe the solution you'd like
Enable new linter flags exposed by typescript in recent versions by defalt
Relevant blog posts:
--noUncheckedIndexedAccess--noPropertyAccessFromIndexSignature--noImplicitOverride--useUnknownInCatchVariables--exactOptionalPropertyTypesDescribe alternatives you've considered
I just have to add these flags manually to
tsconfig.jsonThe text was updated successfully, but these errors were encountered: