Typescript - 重复标识符错误 - const x: ({ y: string, z: string }) => string;

Typescript - Duplicate identifier error - const x: ({ y: string, z: string }) => string;

为什么下面的代码在参数中标记strings会报错Duplicate identifier 'string'.(2300)

const append: ({ first: string, second: string }) => string = ({ first, second }) => first + second;

console.log(append({ first: "a", second: "b" }));

不过,它可以正确编译和运行。

复制

你没有正确定义类型,你想要

const append: (input: { first: string, second: string }) => string = ({ first, second }) => first + second;

在更明确的条目中,这与:

interface Input {
    first: string;
    second: string;
}

interface Append {
    (input: Input): string;
}

const append: Append = ({first, second}) => {
    return first + second;
}