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

A member of Function.prototype can accessible from a type which is intersected with an arrow function, type argument, and nominal branding members but it's not assignable to the Function typed argument #38497

Closed
acid-chicken opened this issue May 12, 2020 · 1 comment

Comments

@acid-chicken
Copy link

acid-chicken commented May 12, 2020

TypeScript Version: 3.9.2

Search Terms:

Expected behavior:

TS2345 should NOT occur (It did not happen in ver 3.8.3).

Actual outcomes:

TS2345 is raised as follows:

Argument of type 'T & { readonly [fooBrand]?: undefined; readonly [barBrand]?: undefined; } & Callable' is not assignable to parameter of type 'Function'. Type 'T & { readonly [fooBrand]?: undefined; readonly [barBrand]?: undefined; } & Callable' is missing the following properties from type 'Function': apply, call, bind, toString, and 6 more.

Related Issues:

#36696?

Code

declare const fooBrand: unique symbol
declare const barBrand: unique symbol

type Callable = (...args: readonly any[]) => any
type CallableXPlugin = {
    readonly [fooBrand]?: never
    readonly [barBrand]?: never
} & Callable
type FooXPlugin = {
    readonly [fooBrand]: 0
    readonly [barBrand]?: never
}
type BarXPlugin = {
    readonly [fooBrand]?: never
    readonly [barBrand]: 0
}
type XPlugin = CallableXPlugin | FooXPlugin | BarXPlugin

function isCallable(x: XPlugin): x is CallableXPlugin {
    return typeof x == 'function'
}
function yo<T extends XPlugin>(x: T) {
    if (isCallable(x)) {
        x.apply(null) // no error
        Reflect.apply(x, null, [] as const) // error!
    }
}
Output
"use strict";
function isCallable(x) {
    return typeof x == 'function';
}
function yo(x) {
    if (isCallable(x)) {
        x.apply(null); // no error
        Reflect.apply(x, null, []); // error!
    }
}
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}

Playground Link: Provided

@acid-chicken
Copy link
Author

I'm sorry, it seems that this is a duplicate of #38549.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant