-
-
Notifications
You must be signed in to change notification settings - Fork 14
Description
I attempted to upgrade from [email protected]
to [email protected]
, but there are breaking changes in [email protected]
which prevent the upgrade.
Restrictions on Assignability to Conditional Types
TypeScript no longer allows types to be assignable to conditional types that use infer, or that are distributive. Doing so previously often ended up causing major performance issues. For more information, see the specific change on GitHub.
The following code seems to make use of this feature:
Lines 186 to 197 in 4715af9
async handle<C extends MainIpcChannelName, T extends FunctionPropertyNames<MainIpcHandlers[C]>>( | |
channel: C, | |
name: T, | |
/** @todo now we only take the FIRST parameter of each handler -- should we take them all? */ | |
data?: Parameters<MainIpcHandlers[C][T]>[0] | |
) { | |
/** @remark (6/25/20) cannot properly type-check this call | |
* without support for "correlated record types", see e.g. | |
* (https://github.com/Microsoft/TypeScript/issues/30581) | |
*/ | |
return this._eventHandlers[channel][name](data as any); | |
} |
Lines 12 to 17 in ab309d3
export type FunctionPropertyNames<T> = { [K in keyof T]: K extends string ? (T[K] extends Function ? K : never) : never }[keyof T]; | |
/* -- Invoker ------------------------------------------- */ | |
interface Invokable { | |
invoke: (channel: string, ...args: any[]) => void; |
noteworthy/src/main/MainIPC.ts
Lines 25 to 47 in 4715af9
declare global { | |
namespace Noteworthy { | |
export interface MainIpcHandlers { | |
// plugins can add additional handler types by | |
// augmenting this interface with type declarations | |
} | |
} | |
} | |
export interface DefaultMainIpcHandlers { | |
lifecycle: MainIpc_LifecycleHandlers; | |
file: MainIpc_FileHandlers; | |
theme: MainIpc_ThemeHandlers; | |
shell: MainIpc_ShellHandlers; | |
dialog: MainIpc_DialogHandlers; | |
tag: MainIpc_TagHandlers; | |
outline: MainIpc_OutlineHandlers; | |
metadata: MainIpc_MetadataHandlers; | |
navigation: MainIpc_NavigationHandlers; | |
}; | |
export type MainIpcHandlers = Noteworthy.MainIpcHandlers & DefaultMainIpcHandlers | |
export type MainIpcChannelName = keyof MainIpcHandlers; |
I receive the following compile error:
ERROR in /home/benjamin/projects/noteworthy/src/main/app.ts
190:21-42
[tsl] ERROR in /home/benjamin/projects/noteworthy/src/main/app.ts(190,22)
TS2344: Type 'MainIpcHandlers[C][T]' does not satisfy the constraint '(...args: any) => any'.
Type 'MainIpcHandlers[C][FunctionPropertyNames<MainIpcHandlers[C]>]' is not assignable to type '(...args: any) => any'.
Type 'MainIpcHandlers[C][keyof MainIpcHandlers[C] extends string ? MainIpcHandlers[C][string & keyof MainIpcHandlers[C]] extends Function ? string & keyof MainIpcHandlers[C] : never : never]' is not assignable to type '(...args: any) => any'.
Type 'MainIpcHandlers[C][MainIpcHandlers[C][string] extends Function ? string : never]' is not assignable to type '(...args: any) => any'.
Type 'MainIpcHandlers[C][string]' is not assignable to type '(...args: any) => any'.
ERROR in /home/benjamin/projects/noteworthy/src/main/app.ts
196:9-43
[tsl] ERROR in /home/benjamin/projects/noteworthy/src/main/app.ts(196,10)
TS2349: This expression is not callable.
Type 'unknown' has no call signatures.
For more information see microsoft/TypeScript#46429.