diff --git a/libs/core/src/lib/declarations/known-keys.d.ts b/libs/core/src/lib/declarations/known-keys.d.ts new file mode 100644 index 00000000..ced16ee5 --- /dev/null +++ b/libs/core/src/lib/declarations/known-keys.d.ts @@ -0,0 +1,22 @@ +/** + * Get the known keys (i.e. no index signature) of T. + * + * @example +```typescript +interface Options { + key: string; + title: string; + [dataProperty: string]: string | number; +} + +type KnownKeysOfOptions = KnownKeys; // 'key' | 'title'; +// (vs. type KeysOfOptions = keyof Options // string | number;) +``` + + * Taken from https://stackoverflow.com/questions/51465182/typescript-remove-index-signature-using-mapped-types + */ +export type KnownKeys = { [K in keyof T]: string extends K ? never : number extends K ? never : K } extends { + [_ in keyof T]: infer U +} + ? U + : never; diff --git a/libs/core/src/lib/declarations/omit.d.ts b/libs/core/src/lib/declarations/omit.d.ts index 8a7a8923..1affee35 100644 --- a/libs/core/src/lib/declarations/omit.d.ts +++ b/libs/core/src/lib/declarations/omit.d.ts @@ -1,4 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -export type Omit = Pick>; +import { KnownKeys } from './known-keys'; + +export type Omit = Pick & keyof T, K>>; diff --git a/libs/core/src/lib/declarations/public-api.d.ts b/libs/core/src/lib/declarations/public-api.d.ts index 887206a2..11137158 100644 --- a/libs/core/src/lib/declarations/public-api.d.ts +++ b/libs/core/src/lib/declarations/public-api.d.ts @@ -1,5 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +export * from './index-signature'; +export * from './known-keys'; export * from './omit'; export * from './StringMap'; diff --git a/libs/fabric/src/lib/components/command-bar/command-bar.component.ts b/libs/fabric/src/lib/components/command-bar/command-bar.component.ts index bcef9d15..d3d276c9 100644 --- a/libs/fabric/src/lib/components/command-bar/command-bar.component.ts +++ b/libs/fabric/src/lib/components/command-bar/command-bar.component.ts @@ -2,7 +2,21 @@ // Licensed under the MIT License. import { InputRendererOptions, Omit, ReactWrapperComponent } from '@angular-react/core'; -import { AfterContentInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, ElementRef, EventEmitter, Input, OnDestroy, Output, QueryList, Renderer2, ViewChild } from '@angular/core'; +import { + AfterContentInit, + ChangeDetectionStrategy, + ChangeDetectorRef, + Component, + ContentChild, + ElementRef, + EventEmitter, + Input, + OnDestroy, + Output, + QueryList, + Renderer2, + ViewChild, +} from '@angular/core'; import { ICommandBarItemProps, ICommandBarProps } from 'office-ui-fabric-react/lib/CommandBar'; import { IContextualMenuItem } from 'office-ui-fabric-react/lib/ContextualMenu'; import { Subscription } from 'rxjs'; @@ -10,7 +24,12 @@ import { OnChanges, TypedChanges } from '../../declarations/angular/typed-change import omit from '../../utils/omit'; import { mergeItemChanges } from '../core/declarative/item-changed'; import { CommandBarItemChangedPayload, CommandBarItemDirective } from './directives/command-bar-item.directives'; -import { CommandBarFarItemsDirective, CommandBarItemsDirective, CommandBarItemsDirectiveBase, CommandBarOverflowItemsDirective } from './directives/command-bar-items.directives'; +import { + CommandBarFarItemsDirective, + CommandBarItemsDirective, + CommandBarItemsDirectiveBase, + CommandBarOverflowItemsDirective, +} from './directives/command-bar-items.directives'; @Component({ selector: 'fab-command-bar', @@ -195,9 +214,10 @@ export class FabCommandBarComponent extends ReactWrapperComponent iconRenderer({ contextualMenuItem: item }), - } as any /* NOTE: Fix for wrong typings of `onRenderIcon` in office-ui-fabric-react */, + iconRenderer && + ({ + onRenderIcon: (item: IContextualMenuItem) => iconRenderer({ contextualMenuItem: item }), + } as any) /* NOTE: Fix for wrong typings of `onRenderIcon` in office-ui-fabric-react */, renderer && ({ onRender: (item, dismissMenu) => renderer({ item, dismissMenu }) } as Pick) ) as ICommandBarItemProps; @@ -205,7 +225,6 @@ export class FabCommandBarComponent extends ReactWrapperComponent extends Omit { - readonly [propertyName: string]: any; readonly renderIcon?: InputRendererOptions; readonly render?: InputRendererOptions; readonly data?: TData; diff --git a/tsconfig.json b/tsconfig.json index 5d1aa609..c8ba5d27 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "typeRoots": ["node_modules/@types"], "lib": ["es2017", "dom"], "baseUrl": ".", + "skipLibCheck": true, "paths": { "@angular-react/*": ["libs/*"], "@angular-react/core": ["libs/core/src/index.ts"],