Duplicate Function Implementation

I have one file, app.ts under my scripts folder, that gets copied to wwwroot/scripts by a gulp task. After the gulp task runs, I now also have a wwwroot/scripts/app.ts file, in which the sole function is red-underlined as duplicate. Is this normal, or is my gulp task, below, declared incorrectly?

var paths = {
    scripts: ["scripts/**/*.js", "scripts/**/*.ts", "scripts/**/*.map"]
};

gulp.task("default", function() {
    gulp.src(paths.scripts).pipe(gulp.dest("wwwroot/scripts"));
});

I see the raw app.ts file, from the root scripts folder also gets built into *.js and *.js.map files. Could this have something to do with the 'false positive' duplicate function?

Answers:

Answer

Don't copy the .ts files. You only need the compiled .js files in the scripts directory (unless you are doing something unusual with TypeScript source from there).

Then in your tsconfig.json file, add an exclude directive to exclude wwwroot/scripts/**/* in your IDE.

Answer

//VSCODE This is an issue from VSCode. To fix it execute the following command

tsc --init
//to initialize the tsconfig.json in the folder.

//VISUAL STUDIO In order to prevent functions to be in global scope, you can add export {}; on top (or just export this function):

// 1.ts
export {};

function test(){
    console log("File 1 Error");
}
// 2.ts
export {};

function test(){
    console.log("File 2 Error");
}
Answer

1- When you call glup with 2 references to the same code the .ts and .js he is going to transpila .. the .ts in to .js soo that's why you have 2 files.

You can try this:

var paths = {
    scripts: ["scripts/**/*.js", "scripts/**/*.map"]
};

gulp.task("default", function() {
    gulp.src(paths.scripts).pipe(gulp.dest("wwwroot/scripts"));
});

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.