mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Telemetry-Tools] Add support for Omit<>
(#121730)
This commit is contained in:
parent
e28340071b
commit
cc3772c9e8
3 changed files with 18 additions and 1 deletions
|
@ -156,4 +156,14 @@ describe('getDescriptor', () => {
|
|||
prop2: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
|
||||
});
|
||||
});
|
||||
|
||||
it('serializes OmitIndexedAccessType', () => {
|
||||
const usageInterface = usageInterfaces.get('OmitIndexedAccessType')!;
|
||||
const descriptor = getDescriptor(usageInterface, tsProgram);
|
||||
expect(descriptor).toEqual({
|
||||
prop3: { kind: ts.SyntaxKind.StringKeyword, type: 'StringKeyword' },
|
||||
prop4: { kind: ts.SyntaxKind.StringLiteral, type: 'StringLiteral' },
|
||||
prop5: { kind: ts.SyntaxKind.FirstLiteralToken, type: 'FirstLiteralToken' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import * as ts from 'typescript';
|
||||
import { uniqBy, pick } from 'lodash';
|
||||
import { uniqBy, pick, omit } from 'lodash';
|
||||
import {
|
||||
getResolvedModuleSourceFile,
|
||||
getIdentifierDeclarationFromSource,
|
||||
|
@ -236,6 +236,12 @@ export function getDescriptor(node: ts.Node, program: ts.Program): Descriptor |
|
|||
const pickPropNames = getConstraints(node.typeArguments![1], program);
|
||||
return pick(parentDescriptor, pickPropNames);
|
||||
}
|
||||
// Support `Omit<SOMETHING, 'prop1' | 'prop2'>`
|
||||
if (symbolName === 'Omit') {
|
||||
const parentDescriptor = getDescriptor(node.typeArguments![0], program);
|
||||
const omitPropNames = getConstraints(node.typeArguments![1], program);
|
||||
return omit(parentDescriptor, omitPropNames);
|
||||
}
|
||||
|
||||
const declaration = (symbol?.getDeclarations() || [])[0];
|
||||
if (declaration) {
|
||||
|
|
|
@ -65,3 +65,4 @@ export type RecordWithKnownProps = Record<MappedTypeProps, number>;
|
|||
export type RecordWithKnownAllProps = Record<MappedTypeAllProps, number>;
|
||||
|
||||
export type IndexedAccessType = Pick<WithUnion, 'prop1' | 'prop2'>;
|
||||
export type OmitIndexedAccessType = Omit<WithUnion, 'prop1' | 'prop2'>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue