类型“字符串”没有呼叫签名

时间:2020-10-28 22:42:11

标签: javascript typescript jestjs

我不知道这到底是怎么了,为什么TS会抱怨。我一定会错过一些我不了解的TS:

App.js

function fullName(firstName: string, lastName: string): string {
  return `${firstName} ${lastName}`;
}

function toUser(view: any, body: any, emailAddress: any) {
  const fullName: string = fullName(firstName, lastName);
  ...
}

错误:

 Type 'String' has no call signatures.

    86  const fullName: string = fullName(firstName, lastName);

TS2448: Block-scoped variable 'fullName' used before its declaration.

    86  const fullName: string = fullName(firstName, lastName);

const fullName: string = fullName(firstName, lastName);
                  ~~~~~~~~
        'fullName' is declared here.

error TS2454: Variable 'fullName' is used before being assigned.

    86  const fullName: string = fullName(firstName, lastName);

enter image description here

1 个答案:

答案 0 :(得分:2)

函数和变量具有相同的名称。您正在屏蔽该功能。