Using Typescript with Gulp 4 and browser-sync is a powerful combination for front-end development

Could use some assistance with setting up my ts-project. Appreciate any help in advance. Have looked around for a solution in the gulpfile.ts but haven't found one yet.

//- package.json 

{
  "name": "cdd",
  "version": "1.0.0",
  "description": "",
  "main": "index.html",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "gulp": "gulp"
  },
  "author": "vssadineni",
  "license": "UNLICENSED",
  "devDependencies": {
    "@types/browser-sync": "^2.26.1",
    "@types/gulp": "^4.0.6",
    "@types/gulp-less": "0.0.31",
    "@types/node": "^12.12.7",
    "browser-sync": "^2.26.7",
    "gulp": "^4.0.2",
    "gulp-less": "^4.0.1",
    "gulp-typescript": "^5.0.1",
    "path": "^0.12.7",
    "ts-node": "^8.5.0",
    "typescript": "^3.7.2"
  }
}

//
//***********
//***********
//- My Gulpfile.ts

import gulp from 'gulp';
import less from 'gulp-less';
import g_ts from 'gulp-typescript';
import path from 'path';
import bSync from 'browser-sync';

let reload = bSync.reload;
bSync.create();

const ts = g_ts.createProject('tsconfig.json');
const paths = {
  style: {
    src: 'less/**/style.less',
    dest: 'dest/css'
  },
  scripts: {
    src: 'ts/**/*.ts',
    dest: 'dest/js'
  }
}

//- less css
export function styles() {
  return gulp.src(paths.style.src)
    .pipe(less({
      paths: [path.join(__dirname, 'less', 'includes')]
    })).on('error', console.error.bind(console))
    .pipe(gulp.dest(paths.style.dest))
}

//- Browser Sync
export function browserSync(done: () => any) {
  bSync.init({
    server: {
      baseDir: './'
    },
    port: 4005
  });
  done();
}

//- TypeScripts Transpiling
export function types(done: () => any) {
  return ts.src()
    .pipe(ts())
    .pipe(gulp.src(paths.scripts.dest));
  done();
}


function Watch() {
  gulp.watch(paths.style.src, styles, reload)
  gulp.watch(paths.scripts.src, types, reload)
}

const sync = gulp.parallel(Watch, gulp.series(styles, types));
const build = gulp.series(gulp.parallel([styles, types], browserSync));

export {
  Watch as watch
}
const build = gulp.series(gulp.parallel(styles, types))
export default build;
//-- tscongif.json

{
  "compilerOptions": {
    "target": "ES2018",
    "module": "commonjs",
    "declaration": true,
    "sourceMap": true,
    "outDir": "./dest",
    "strict": true,
    "moduleResolution": "node",
    "baseUrl": "./",
    "typeRoots": [
      "./node_modules/@types"
    ],
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "sourceRoot": "src",
    "forceConsistentCasingInFileNames": true,
    "declarationDir": "dest/js/d"
  }
}

When running gulp, encountering the following error:

[17:17:03] Requiring external module ts-node/register

C:\vijay\projects\customDropdown\node_modules\ts-node\src\index.ts:293 return new TSError(diagnosticText, diagnosticCodes) ^ TSError: ⨯ Unable to compile TypeScript: gulpfile.ts:57:7 - error TS2451: Cannot redeclare block-scoped variable 'build'.

57 const build = gulp.series(gulp.parallel([styles, types], browserSync)); ~~~~~ gulpfile.ts:60:7 - error TS2451: Cannot redeclare block-scoped variable 'build'.

60 const build = gulp.series(gulp.parallel(styles, g_ts)) ~~~~~ gulpfile.ts:52:31 - error TS2559: Type '() => ReadWriteStream' has no properties in common with type 'WatchOptions'.

52 gulp.watch(paths.style.src, styles, reload) ~~~~~~ gulpfile.ts:53:33 - error TS2559: Type '(done: () => any) => ReadWriteStream' has no properties in common with type 'WatchOptions'.

53 gulp.watch(paths.scripts.src, types, reload) ~~~~~ gulpfile.ts:57:41 - error TS2345: Argument of type '((done: () => any) => ReadWriteStream)[]' is not assignable to parameter of type 'Task'. Type '((done: () => any) => ReadWriteStream)[]' is not assignable to type 'string'.

57 const build = gulp.series(gulp.parallel([styles, types], browserSync)); ~~~~~~~~~~~~~~~

at createTSError (C:\vijay\projects\customDropdown\node_modules\ts-node\src\index.ts:293:12)
at reportTSError (C:\vijay\projects\customDropdown\node_modules\ts-node\src\index.ts:297:19)
at getOutput (C:\vijay\projects\customDropdown\node_modules\ts-node\src\index.ts:399:34)
at Object.compile (C:\vijay\projects\customDropdown\node_modules\ts-node\src\index.ts:457:32)
at Module.m._compile (C:\vijay\projects\customDropdown\node_modules\ts-node\src\index.ts:530:43)
at Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Object.require.extensions.(anonymous function) [as .ts] (C:\vijay\projects\customDropdown\node_modules\ts-node\src\index.ts:533:12)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)

Addressed most issues, but now facing only one.

error TS2345: Argument of type '(() => ReadWriteStream)[]' is not assignable to parameter of type 'Task'. Type '(() => ReadWriteStream)[]' is not assignable to type 'string'.

Answer №1

This issue is completely unrelated to typescript/gulp. It appears that you have mistakenly defined the function build two times in your code.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method to add data to a child array located within a nested array?

Struggling to create an array that will display data in the following format: Healthcare -- Insights driven by data for improved healthcare -- Urban Analytics Transport -- Urban Analytics Cities -- Urban Analytics I have attempted ...

Integrating fresh components into a JSON structure

I've been attempting to insert a new element into my JSON, but I'm struggling to do it correctly. I've tried numerous approaches and am unsure of what might be causing the issue. INITIAL JSON INPUT { "UnitID":"1148", "UNIT":"202B", "Sp ...

ESLint refuses to be turned off for a particular file

I am in the process of creating a Notes.ts file specifically for TypeScript notes. I require syntax highlighting but do not want to use eslint. How can I prevent eslint from running on my notes file? Directory Structure root/.eslintignore root/NestJS.ts r ...

Can you explain how to invoke a class with express().use function?

Currently, I am delving into learning Node JS with TypeScript but have hit a roadblock with a particular issue. In my app.ts file, I have initialized the express and attempted to call the router class inside the app.use() method, only to encounter an error ...

Tips for fetching individual item information from Firebase real-time database using Angular 9 and displaying it in an HTML format

product.component.ts import { AngularFireDatabase } from '@angular/fire/database'; import { ProductService } from './../product.service'; import { ActivatedRoute } from '@angular/router'; import { Component, OnInit} from &apo ...

An error occurred while trying to load the configuration "next/core-web-vitals" for extension

If you're embarking on a new project using NextJs and TypeScript, chances are you may encounter the following error: Failed to load config "next/core-web-vitals" to extend from. Wondering how to resolve this issue? ...

Leveraging the OpenLayers Map functionality within an Angular service

I am curious to learn if there is a way to utilize a service in Angular for creating an OpenLayers map and then passing that service to other components to update the map based on interactions within those components. I have outlined my approach below. Des ...

What is the method for launching Chrome synchronously in Selenium WebDriver using createSession()?

After executing the code below using Selenium WebDriver to launch a Chrome browser: import { Driver } from 'selenium-webdriver/chrome'; Driver.createSession(); console.log("I've launched!"); I'm encountering an issue where "I've ...

Tips on Resolving TypeError: Unable to Access Undefined PropertyAre you encountering a

I'm currently facing an issue while writing unit test cases using Jest in my Angular project. Whenever I attempt to run my test file, the following errors occur: TypeError: Cannot read property 'features' of undefined TypeError: Cannot read ...

Testing a React component that uses useParams: A step-by-step guide

I've been working on creating a BBS App using TypeScript, React, React Router, and React Testing Library. However, I've encountered an issue where a component utilizing useParams is not passing a test. Interestingly, it seems to be working correc ...

Using rxjs for exponential backoff strategy

Exploring the Angular 7 documentation, I came across a practical example showcasing the usage of rxjs Observables to implement an exponential backoff strategy for an AJAX request: import { pipe, range, timer, zip } from 'rxjs'; import { ajax } f ...

Keep track of the input values by storing them in an array after they are

Creating an Angular application to read barcodes. barcode-scanner.component.html <form #f="ngForm" class="mt-3 text-center" id="myform" (ngSubmit)="onSubmit(f)"> <div class="text-center"> <input type="text" maxlength= ...

Unable to define the type for the style root in Typescript

I am encountering an error that is asking me to code the following types in the root tag: No overload matches this call. Overload 1 of 2, '(style: Styles<Theme, {}, "root">, options?: Pick<WithStylesOptions<Theme>, "fli ...

Challenges in handling asynchronous data within static JSON objects in Angular2

I have a service set up with some static objects that are being utilized in my UI. fetchRulesVariables() fetchRuleVariables() { let variables = [ { name: 'Credit Funding Type', id: 1, multiple: ...

Issues with my transpiled and typed TypeScript npm module: How can I effectively use it in a TypeScript project?

I'm trying to experiment with TypeScript. Recently, I created a simple "hello world" TypeScript module and shared it on npm. It's very basic, just has a default export: export default function hello(target: string = 'World'): void { ...

Transitioning menus in Ionic 2

I followed the instructions in the Ionic 2 menu documentation and tried to display the menu in a specific way: My intention was to have the menu displayed below the content page while keeping the menu button visible. However, when I ran my app, it appear ...

Tips for creating a universal function for two interlinked types

My goal is to establish an abstract relationship between different sub-types of Message and Response, allowing for a generic function that takes a Message as input and returns a corresponding Response. Specifically, when the function is called with type Me ...

Modifying audio output in a React element

I am trying to incorporate background music into my React app using TypeScript. However, I am encountering an issue where changing the music in the parent component does not affect the sound playing in the child node. import React from 'react'; ...

Is there a way to stop Material UI from dulling the color of my AppBar when using dark mode in my theme?

When I use mode: "dark" in my Material UI theme, it causes the color of my AppBar to become desaturated. Switching it to mode: "light" resolves this issue. This is how my theme is configured: const theme = createTheme({ palette: { ...

Error occurs in Typescript when attempting to store data in a record using a pointer

When working with nodes and organizing them into a tree structure, I encounter an issue: This is the definition of the interface: interface IDataObj { children: IDataObj[], frontmatter : { type: string, title: string, path: string}, name: str ...