[Telemetry Tools] Merge array of constraints (#79654)
This commit is contained in:
parent
6b80eb20ab
commit
ed825398c6
|
@ -148,6 +148,17 @@ describe('getDescriptor', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('serializes RecordWithKnownAllProps', () => {
|
||||
const usageInterface = usageInterfaces.get('RecordWithKnownAllProps')!;
|
||||
const descriptor = getDescriptor(usageInterface, tsProgram);
|
||||
expect(descriptor).toEqual({
|
||||
prop1: { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
|
||||
prop2: { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
|
||||
prop3: { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
|
||||
prop4: { kind: ts.SyntaxKind.NumberKeyword, type: 'NumberKeyword' },
|
||||
});
|
||||
});
|
||||
|
||||
it('serializes IndexedAccessType', () => {
|
||||
const usageInterface = usageInterfaces.get('IndexedAccessType')!;
|
||||
const descriptor = getDescriptor(usageInterface, tsProgram);
|
||||
|
|
|
@ -88,7 +88,11 @@ export function getConstraints(node: ts.Node, program: ts.Program): any {
|
|||
|
||||
if (ts.isUnionTypeNode(node)) {
|
||||
const types = node.types.filter(discardNullOrUndefined);
|
||||
return types.map((typeNode) => getConstraints(typeNode, program));
|
||||
return types.reduce<any>((acc, typeNode) => {
|
||||
const constraints = getConstraints(typeNode, program);
|
||||
const contraintsArray = Array.isArray(constraints) ? constraints : [constraints];
|
||||
return [...acc, ...contraintsArray];
|
||||
}, []);
|
||||
}
|
||||
|
||||
if (ts.isLiteralTypeNode(node) && ts.isLiteralExpression(node.literal)) {
|
||||
|
|
|
@ -58,6 +58,10 @@ export type TypeAliasWithRecord = Usage & Record<string, number>;
|
|||
|
||||
export type MappedTypeProps = 'prop1' | 'prop2';
|
||||
|
||||
export type MappedTypeExtraProps = 'prop3' | 'prop4';
|
||||
|
||||
export type MappedTypeAllProps = MappedTypeProps | MappedTypeExtraProps;
|
||||
|
||||
export interface MappedTypes {
|
||||
mappedTypeWithExternallyDefinedProps: {
|
||||
[key in MappedTypeProps]: number;
|
||||
|
@ -68,5 +72,6 @@ export interface MappedTypes {
|
|||
}
|
||||
|
||||
export type RecordWithKnownProps = Record<MappedTypeProps, number>;
|
||||
export type RecordWithKnownAllProps = Record<MappedTypeAllProps, number>;
|
||||
|
||||
export type IndexedAccessType = Pick<WithUnion, 'prop1' | 'prop2'>;
|
||||
|
|
Loading…
Reference in a new issue