类型脚本指南给出了“重复功能实现".警告 [英] Typescript guide gives "Duplicate function implementation" warning

查看:36
本文介绍了类型脚本指南给出了“重复功能实现".警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用TypeScript,此刻我正在关注

但是在我的单个文件中没有这个独特功能的其他实现!当我运行 tsc greeter.ts 时,一切正常,并生成了js文件.

完整的 greeter.ts 文件:

 界面Person {firstName:字符串;lastName:字符串;}功能问候者(人:人){返回你好," + person.firstName +" + person.lastName;}var user = {firstName:"Jane",lastName:"User"};console.log(greeter(user)); 

为什么我会收到此警报?怎么解决呢?我查看了这个问题,但我相信这没有关系.

解决方案

这似乎是Visual Studio Code中的错误.GitHub上有一些与此有关的问题,例如此处TypeScript in 5 minutes guide. I'm receiving a strange warning in Visual Studio Code when I hover the mouse over the greeter function name, as shown in the below image. The alert is:

[ts] Duplicate function implementation.

function greeter(person: Person): string (+1 overload)

But there is no other implementation of this unique function in my single file! When I run tsc greeter.ts all works fine and the js file is generated.

The complete greeter.ts file:

interface Person {
    firstName: string;
    lastName: string;
}

function greeter(person: Person) {
    return "Hello, " + person.firstName + " " + person.lastName;
}

var user = { firstName: "Jane", lastName: "User" };

console.log(greeter(user));

Why am I receiving this alert? How to solve it? I took a look in this question, but I believe it isn't related.

解决方案

Looks like this is a bug in Visual Studio Code. There are a few issues on GitHub about this, such as here and here. The comments on the issues imply that it was an issue, then was fixed, and has just become an issue again in v1.12.1.

It looks as if the solution is to run tsc --init to initialize the tsconfig.json in the folder.

这篇关于类型脚本指南给出了“重复功能实现".警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆