-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Cannot read property 'flags' of undefined(3.2.x) #28935
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
Comments
return propType === narrowedPropType ? type : filterType(type, t => isTypeComparableTo(getTypeOfPropertyOfType(t, propName)!, narrowedPropType!)); |
@DanielRosenwasser |
That comment was meant more for anyone who ends up assigned to this issue 😃 |
Here's a repro that crashes with a similar call stack: type Foo = { tag: true, x: number } | { tag: false, y: number } | { [x: string]: string };
function test(foo: Foo) {
if (!foo.tag) {
foo;
}
} The issue is that we assume that each constituent has a discriminant property when it is possible that some don't, but rather have a string index signature. |
@xiaocaibird Just merged what I think is a fix to your issue. Try pulling the next nightly build and let us know what you find. |
+1 same issue here |
Have you tried the nightly build? |
Fix. Thanks!! |
Great! Glad we could fix it quickly. |
TypeScript Version: 3.2.x
Search Terms: Cannot read property 'flags' of undefined
Code
First of all, I am sorry. This is an internal project of our company, I can't provide a git url.
And because of the large amount of code, I still can't find the wrong code snippet.
Our project is still working in the previous version(3.1.x).
I found this problem in 3.2.1,and I found some related issues at the time.
I was hoping it could be fixed together, but no.
Expected behavior: Compile
Actual behavior:
TypeError: Cannot read property 'flags' of undefined
at isFreshLiteralType (/project/news-manage/node_modules/typescript/lib/tsc.js:33326:28)
at isTypeRelatedTo (/project/news-manage/node_modules/typescript/lib/tsc.js:34425:17)
at isTypeComparableTo (/project/news-manage/node_modules/typescript/lib/tsc.js:33930:20)
at /project/news-manage/node_modules/typescript/lib/tsc.js:37851:102
at Object.filter (/project/news-manage/node_modules/typescript/lib/tsc.js:340:31)
at filterType (/project/news-manage/node_modules/typescript/lib/tsc.js:37422:35)
at narrowTypeByDiscriminant (/project/news-manage/node_modules/typescript/lib/tsc.js:37851:63)
at narrowTypeByTruthiness (/project/news-manage/node_modules/typescript/lib/tsc.js:37858:28)
at narrowType (/project/news-manage/node_modules/typescript/lib/tsc.js:38161:32)
at getTypeAtFlowCondition (/project/news-manage/node_modules/typescript/lib/tsc.js:37730:36)
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: