Skip to content

Commit ec2c324

Browse files
committed
fix(api): prevent non-existing properties
1 parent d9139b5 commit ec2c324

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/api/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ type Narrow<A> = Cast<A,
2121
| ({ [K in keyof A]: Narrow<A[K]> })
2222
>
2323

24+
// Prevent properties not in PluginDescriptor
25+
// We need this because of the `extends` in the generic TDescriptor
26+
type Exact<C, T> = {
27+
[K in keyof C]: K extends keyof T ? T[K] : never
28+
}
29+
2430
export type SetupFunction<TSettings = any> = (api: DevtoolsPluginApi<TSettings>) => void
2531

2632
export function setupDevtoolsPlugin<
27-
TDescriptor extends PluginDescriptor = PluginDescriptor,
33+
TDescriptor extends Exact<TDescriptor, PluginDescriptor>,
34+
// @ts-expect-error Type '"settings"' cannot be used to index type 'TDescriptor'.ts(2536)
2835
TSettings = ExtractSettingsTypes<TDescriptor['settings']>,
2936
> (pluginDescriptor: Narrow<TDescriptor>, setupFn: SetupFunction<TSettings>) {
30-
const descriptor = pluginDescriptor as TDescriptor
37+
const descriptor = pluginDescriptor as unknown as PluginDescriptor
3138
const target = getTarget()
3239
const hook = getDevtoolsGlobalHook()
3340
const enableProxy = isProxyAvailable && descriptor.enableEarlyProxy

0 commit comments

Comments
 (0)