-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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 and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a tsconfig option to disallow implicit never and unknown #57406
Comments
Iβm confused β there isnβt a such thing as an βimplicitβ |
I don't know what an "implicit unknown" or "implicit never" are either. Code examples when describing suggestions for a programming language are very helpful. |
with
Btw this obviously not pretty but doesn't create error telling me that there is an array created of type
|
i was wrong with |
I'm not understanding the motivation here. If you create a
Whereas with
When people wanted |
The
I still don't think it's safe:
const obj = { a: [] }
const pushA = <T,>(blah: {a: T[]}, a:T)=>{
blah.a.push(a)
}
pushA(obj, 4)
pushA(obj, "foo")
// obj.a is now an array containing [4, 'foo'] but typed as never[] |
π Search Terms
"never", "unknown", "tsconfig", "implicit"
β Viability Checklist
β Suggestion
never
andunknown
unlikeany
dont have atsconfig.json
option.My suggestion is to add an option to the file similar to
any
.To avoid problems i would suggest to set it as
false
and to later on add it withtrue
to the strict mode in later versions to give people time to adjust.tsconfig
options could look like the following:π Motivating Example
It would lead to cleaner coding and less problems when strict mode is on.
π» Use Cases
Q: What do you want to use this for?
A: To easily get the compiler to show me when there are variables that have unintended
never
/unknown
as datatype.Q. What shortcomings exist with current approaches?
A: People create variables that get read as never/unknown by the compiler and when others try to clean it up later they have a harder time understanding what the intended value should be. It leads to worse code.
Q: What workarounds are you using in the meantime?
A: Using Eslint.
The text was updated successfully, but these errors were encountered: