Skip to content

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

Description

@acid-chicken

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions