Skip to content

normal function type and array function type behave differently with tuple type in function parameters #32438

@hronro

Description

@hronro

TypeScript Version: 3.5.2

Code

function test1 (a: {
    f (n: any[]): void;
}) {}
function test2 (a: {
    f: (n: any[]) => void;
}) {}


test1({
    f ([s]: [string]) {}
});

test2({
    f ([s]: [string]) {}
});

Expected behavior:
Type check for test1 and test2 should have same result: both of them should pass type check, or neither of them pass type check

Actual behavior:
test1 passed type check, test2 didn't:

Type '([s]: [string]) => void' is not assignable to type '(n: any[]) => void'.
  Types of parameters '__0' and 'n' are incompatible.
    Property '0' is missing in type 'any[]' but required in type '[string]'.

Playground Link:
https://www.typescriptlang.org/play/index.html?experimentalDecorators=true&emitDecoratorMetadata=true#code/GYVwdgxgLglg9mABFApgZygRkQCgIYBciA3gFCIWLC5hF5gCeA2gLoCURAbnDACYDcpAL5sSQ0qEiwEydFABMuQiXKVgRHLUT1m7RAF4AfIm59BIsaSuoMmHGUpVcTNCyIuoAJxhgA5nuJxEUFSGwV7VQpqHBc3RA9vPwCgtn4gA

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions