7

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?

ProfK
  • 49,207
  • 121
  • 399
  • 775

4 Answers4

3

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.

Josh Wulf
  • 4,727
  • 2
  • 20
  • 34
0

//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");
}
Chukwuemeka Maduekwe
  • 6,687
  • 5
  • 44
  • 67
0

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"));
});
3pa2
  • 5
  • 1
  • 4
0

You need to generate a tsconfig.json file. You can generate the file using a simple command. Open terminal and type "tsc -init".