We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
TypeScript Version: 2.1.4
Code
(--strictNullChecks)
interface Store { value: string | undefined } export function get<K extends keyof Store>( store: Store, fieldName: K ): Store[K] { if (store[fieldName] == undefined) throw(fieldName + " is undefined!"); return store[fieldName] } const store: Store = { value: "stuff" } const result = get(store, "value").replace("stuff", "otherstuff")
Expected behavior:
(It's possible to narrow the resulting type of get to exclude undefined values)
get
Actual behavior:
Type error is reported: get(a, "value") is possibly undefined.
I'd propose an operator which could be used to express that the mapped type does not contain undefined. Consider the use of bang (!) operator below:
undefined
export function get<K extends keyof Store>( store: Store, fieldName: K ): Store[K]! { if (store[fieldName] == undefined) throw(fieldName + " is undefined!"); return store[fieldName] }
The text was updated successfully, but these errors were encountered:
I believe this is what you are looking for #12578
Sorry, something went wrong.
Yep
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
Problem
TypeScript Version: 2.1.4
Code
(--strictNullChecks)
Expected behavior:
(It's possible to narrow the resulting type of
get
to exclude undefined values)Actual behavior:
Type error is reported: get(a, "value") is possibly undefined.
Proposal
I'd propose an operator which could be used to express that the mapped type does not contain
undefined
. Consider the use of bang (!) operator below:The text was updated successfully, but these errors were encountered: