We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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: 3.7.2
Search Terms: different behavior when destructuring typescript strictNullChecks
Code
interface Data { readonly name: string; readonly id: number; } interface MainInputLoading { readonly isLoading: true; readonly data: null; } interface MainInputLoaded { readonly isLoading: false; readonly data: Data; } type MainInput = MainInputLoading | MainInputLoaded; function main({ isLoading, data }: MainInput) { if (isLoading) { return; } console.log(data.id); // Fails } function altMain(input: MainInput) { if (input.isLoading) { return; } console.log(input.data.id); // Doesn't fail }
Expected behavior: They should behave exactly the same as TS should be able to know that the destructured props still refer to the original object.
Actual behavior: In one case we have an error and in the other we don't.
Playground Link: https://codesandbox.io/s/sweet-williamson-7bs9d
Related Issues: No
The text was updated successfully, but these errors were encountered:
Looks like duplicate of #33097, #28599, and many other which in the end are related to #12184
Sorry, something went wrong.
Duplicated then.
No branches or pull requests
TypeScript Version: 3.7.2
Search Terms: different behavior when destructuring typescript strictNullChecks
Code
Expected behavior: They should behave exactly the same as TS should be able to know that the destructured props still refer to the original object.
Actual behavior: In one case we have an error and in the other we don't.
Playground Link: https://codesandbox.io/s/sweet-williamson-7bs9d
Related Issues: No
The text was updated successfully, but these errors were encountered: