Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 893
Bruno Peres Avatar asked May 26 '17 02:05

Bruno Peres


2 Answers

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.

like image 184
Andrew Li Avatar answered Sep 24 '22 00:09

Andrew Li


If you have both the src file (typescript) and the transpiled file (javascript) in the same directory and open up the javascript file in VS Code then you'll get the error. Output the transpiled file into a directory and it will not error. Use the --outDir flag: tsc --outDir ./dist greeter.ts

Got this problem in version 1.26.1 of VS Code. Generating the tsconfig.json file did not make the error go away for me.

like image 32
Eric Pitcher Avatar answered Sep 26 '22 00:09

Eric Pitcher