Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

javascript - Typescript guide gives "Duplicate function implementation" warning

I'm getting started with TypeScript and at moment I'm following the 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)

Duplicate function implementation warning.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...