Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] address breaking changes to conditional types in [email protected] #30

Open
benrbray opened this issue Feb 28, 2023 · 0 comments
Labels
chore dependencies Pull requests that update a dependency file maintenance It ain't much, but it's honest work

Comments

@benrbray
Copy link
Owner

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:

noteworthy/src/main/app.ts

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);
}

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;

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.

@benrbray benrbray added maintenance It ain't much, but it's honest work dependencies Pull requests that update a dependency file chore labels Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore dependencies Pull requests that update a dependency file maintenance It ain't much, but it's honest work
Projects
None yet
Development

No branches or pull requests

1 participant