Typescript guide gives “Duplicate function implementation” warning

后端 未结 6 1660
小蘑菇
小蘑菇 2020-12-30 20:44

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

相关标签:
6条回答
  • 2020-12-30 21:27

    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.

    0 讨论(0)
  • 2020-12-30 21:33

    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.

    0 讨论(0)
  • 2020-12-30 21:36

    In my case, it seems that if the file didn't import/export anything it wasn't considered a module and VS Code would assume that all the files would get concatenated together. You can fix it by adding an import/export.

    I also went ahead and set my tsconfig to include isolatedModules so that I would get a more helpful error message.

    {
        "isolatedModules": true,
    }
    
    0 讨论(0)
  • 2020-12-30 21:42

    According to this article, add this simple line in the top of your Typescript file export { };

    [index.ts] export { };

    declare const signalR: any;
    declare const moment: any;
    
    0 讨论(0)
  • 2020-12-30 21:48

    When we open both file.ts and the transpiled file.js files and do TSC, this error occurs.
    Please close the transpiled file.js and try again.

    0 讨论(0)
  • 2020-12-30 21:49

    This might be because you don't have a tsconfig.json file for your TypeScript project. Try creating a tsconfig file and write a default "compilerOptions". It worked for me. The tsconfig.json file with default code that I used is :

    {
        "compilerOptions": {
            "module": "commonjs"
        },
        "exclude": [
            "node_modules"
        ]
    }
    

    For more info on VS TypeScript Compiling please refer https://code.visualstudio.com/docs/typescript/typescript-compiling

    0 讨论(0)
提交回复
热议问题