Repository navigation
Add utility function to check for strict option flags - #19427
Conversation
- Correctelly check for noImplicitAny in checker - Correctelly check for noImplicitAny in installTypesForPackage refactor
| return moduleResolution; | ||
| } | ||
|
|
||
| export function getStrictOptionValue(compilerOptions: CompilerOptions, flag: "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "alwaysStrict"): boolean { |
There was a problem hiding this comment.
Is there some way we can brand CompilerOptions internally in the type system such that we cannot use the strict-depending fields directly - they must be accessed through this function?
There was a problem hiding this comment.
Could not think of a way to do that without changing the shape of the compiler options object..
There was a problem hiding this comment.
Documenting exploration for future reference: You can move members into a superclass/superinterface, then override them (marked @internal) with an intersection with never to change the field type to never internally (yet this is not an error for very odd reasons) - however in practice this messes with unit tests (some of which expect to explicitly set fields of those types) and doesn't prevent you from doing things like saying if (compilerOptions.noImplicitAny), which was the goal (as a never member is still considered present) :(
7b68e77 to
d60c640
Compare
Anders Hejlsberg (ahejlsberg)
left a comment
There was a problem hiding this comment.
Approved with the suggested change.
| return moduleResolution; | ||
| } | ||
|
|
||
| export function getStrictOptionValue(compilerOptions: CompilerOptions, flag: "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "alwaysStrict"): boolean { |
There was a problem hiding this comment.
I suggest declaring and using the following type for the flag property:
type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "alwaysStrict";| export type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[] | MapLike<string[]> | PluginImport[] | null | undefined; | ||
|
|
||
| export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "alwaysStrict"; | ||
|
|
There was a problem hiding this comment.
Can this not be in core (since the function itself is internal why not type as well be internal)
This reverts commit cf4ef62.
Follow up on #19390, specifically: https://github.com/Microsoft/TypeScript/pull/19390/files#r146092916.
This change adds a new helper function to access strict flags consistently by checking their value then the
--strictflag value if they are not set. it also: