Skip to content

Commit 59ca73a

Browse files
author
Ben Grynhaus
committed
Fix ICommandBarItemOptions type (again)
1 parent 6d99ee6 commit 59ca73a

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
/**
5+
* An object with a `string`-based index signature.
6+
*/
47
export type StringMap<T = any> = { [index: string]: T };

libs/core/src/lib/declarations/known-keys.d.ts renamed to libs/core/src/lib/declarations/known-keys.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
/**
25
* Get the known keys (i.e. no index signature) of T.
36
*
@@ -15,8 +18,6 @@ type KnownKeysOfOptions = KnownKeys<Options>; // 'key' | 'title';
1518
1619
* Taken from https://stackoverflow.com/questions/51465182/typescript-remove-index-signature-using-mapped-types
1720
*/
18-
export type KnownKeys<T> = { [K in keyof T]: string extends K ? never : number extends K ? never : K } extends {
19-
[_ in keyof T]: infer U
20-
}
21-
? U
22-
: never;
21+
export type KnownKeys<T> = {
22+
[K in keyof T]: string extends K ? never : number extends K ? never : K
23+
} extends { [_ in keyof T]: infer U } ?U: never;
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { KnownKeys } from './known-keys';
5-
4+
/**
5+
* Inverse of `Pick<T, K>`.
6+
*/
67
export type Omit<T, K extends keyof T> = Pick<T, Exclude<KnownKeys<T> & keyof T, K>>;

libs/fabric/src/lib/components/command-bar/command-bar.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
import { InputRendererOptions, Omit, ReactWrapperComponent } from '@angular-react/core';
4+
import { InputRendererOptions, ReactWrapperComponent } from '@angular-react/core';
55
import {
66
AfterContentInit,
77
ChangeDetectionStrategy,
@@ -224,7 +224,10 @@ export class FabCommandBarComponent extends ReactWrapperComponent<ICommandBarPro
224224
}
225225
}
226226

227-
export interface ICommandBarItemOptions<TData = any> extends Omit<ICommandBarItemProps, 'onRender' | 'onRenderIcon'> {
227+
// Not using `Omit` here since it confused the TypeScript compiler and it just showed the properties listed here (`renderIcon`, `render` and `data`).
228+
// The type here is just `Omit` without the generics though.
229+
export interface ICommandBarItemOptions<TData = any>
230+
extends Pick<ICommandBarItemProps, Exclude<KnownKeys<ICommandBarItemProps>, 'onRender' | 'onRenderIcon'>> {
228231
readonly renderIcon?: InputRendererOptions<ICommandBarItemOptionsRenderIconContext>;
229232
readonly render?: InputRendererOptions<ICommandBarItemOptionsRenderContext>;
230233
readonly data?: TData;

0 commit comments

Comments
 (0)