-
Notifications
You must be signed in to change notification settings - Fork 202
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
fix: union types of union types in Records #1933
Conversation
8a0fe2e
to
47af8b9
Compare
@domoritz Much more eloquent solution than my PR. Didn't even notice the existence of the derefType utility. Few comments:
thanks again for all the help on this. I use union types in records extensively in my code and this will help greatly. |
@@ -103,7 +103,7 @@ export class MappedTypeNodeParser implements SubNodeParser { | |||
|
|||
protected getProperties(node: ts.MappedTypeNode, keyListType: UnionType, context: Context): ObjectProperty[] { | |||
return keyListType | |||
.getTypes() | |||
.getFlattenedTypes(derefType) | |||
.filter((type): type is LiteralType => type instanceof LiteralType) | |||
.map((type) => [type, this.mapKey(node, type, context)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map((type) => [type, this.mapKey(node, type, context)]) | |
.reduce((acc: LiteralType[], curr: LiteralType) => { | |
if ( | |
acc.findIndex((val: LiteralType) => { | |
return val.getId() === curr.getId(); | |
}) < 0 | |
) { | |
acc.push(curr); | |
} | |
return acc; | |
}, []) | |
.map((type) => [type, this.mapKey(node, type, context)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use uniqueTypeArray
here instead I think.
512274d
to
12b85ba
Compare
thanks for looking into this so quickly @domoritz |
🚀 PR was released in |
Revised version of #1926 by dpvball
📦 Published PR as canary version:
2.1.1--canary.1933.1cab987.0
✨ Test out this PR locally via: