Mark as referenced aliases in Union that will get emitted as part of decorator metadata#13540
Conversation
| if (node) { | ||
| switch (node.kind) { | ||
| case SyntaxKind.IntersectionType: | ||
| case SyntaxKind.UnionType: |
There was a problem hiding this comment.
why do we allow unions and intersections any ways. we do not serialize them correctly anyways.
There was a problem hiding this comment.
we allow this if the Individual type leads to same identifier. This is to make sure string | null will emit type as string.. E | null results in E and "foo" | "bar" results in string as type
There was a problem hiding this comment.
#13034 added support for E | null to emit it as type in metadata as E
|
|
||
| type voidUndefinedNullOrNeverTypeNode = Token<SyntaxKind.VoidKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.NullKeyword | SyntaxKind.NeverKeyword>; | ||
|
|
||
| function getEntityNameForDecoratoryMetadata(node: TypeNode): EntityName | voidUndefinedNullOrNeverTypeNode { |
There was a problem hiding this comment.
'getEntityNameForDecoratorMetadata'
| } | ||
| } | ||
|
|
||
| function markDecoratorMedataDataTypeNodeAsReferenced(node: TypeNode): void { |
There was a problem hiding this comment.
Just for consistency markDecoratorMedataDataTypeNodeAsReferenced should be markDecoratorMedataDataTypeNodeAsReference
There was a problem hiding this comment.
Could you add comment on why we need this separate from using markTypeNodeAsReferenced
| for (const typeNode of (<UnionOrIntersectionTypeNode>node).types) { | ||
| const individualEntityName = getEntityNameForDecoratoryMetadata(typeNode); | ||
| if (!individualEntityName) { | ||
| // Individual is something like string number |
There was a problem hiding this comment.
is this mean that if each constituent of intersection or union type is a string or number, then return undefined?
Can you note where it will get seriazlied?
| case SyntaxKind.UndefinedKeyword: | ||
| case SyntaxKind.NullKeyword: | ||
| case SyntaxKind.NeverKeyword: | ||
| return <voidUndefinedNullOrNeverTypeNode>node; |
There was a problem hiding this comment.
Why do we return the token here? This function is only used by markDecoratorMedataDataTypeNodeAsReferenced, which in turn only cares if its an EntityName.
| } | ||
|
|
||
| function serializeUnionOrIntersectionType(node: UnionOrIntersectionTypeNode): SerializedTypeNode { | ||
| // Note when updating logic here also update getEntityNameForDecoratoryMetadata |
There was a problem hiding this comment.
getEntityNameForDecoratorMetadata
OneType|null is again treated as object instead of simplifying it
|
Merging this as per @mhegazy 's offline approval. |
Fixes #13449