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

The powerful combination of Vuetify, Inertia, and Typescript creates a

Currently, I am working with Vuetify and Inertia while using Typescript. I am faced with the challenge of passing shared data to the items prop of a vuetify AutoComplete component: <v-autocomplete :items="$page.props.countries"></v-auto ...

Using checkboxes to filter a list within a ReactiveForm can result in a rendering issue

I have implemented a dynamic form that contains both regular input fields and checkboxes organized in a list. There is also an input field provided to filter the checkbox list. Surprisingly, I found out that when using the dot (.) character in the search f ...

Is there a way to export a specific portion of a destructuring assignment?

const { a, ...rest } = { a: 1, b: 2, c: 3 }; If I want to export only the rest object in TypeScript, how can I achieve that? ...

Guide on sending JSON object to Angular custom components

I have implemented a custom element in Angular 7 using the CUSTOM_ELEMENTS_SCHEMA. My app.module.ts code is as follows: export class AppModule { constructor(private injector: Injector) {} ngDoBootstrap() { this.registerCustomElements( ...

Using Next.js, it is not possible to use absolute imports within SASS

Having trouble utilizing @/ imports within my scss files. The variables I need are stored in src/styles/_variables.scss Here is my tsconfig.json: { "compilerOptions": { "lib": ["dom", "dom.iterable", "esnext"], "baseUrl": ".", "allowJs": tr ...

Importing Json in Angular 8: A detailed guide

I recently came across information that you can now directly import JSON in TypeScript 2.9 and made changes to my tsconfig.json file accordingly: { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", " ...

The element event does not trigger an update on the view

I am trying to display the caret position of my editor on a specific place on the website. I have created a directive and service to share variables between the controller and directive. Inside the directive, I have enabled events like "keyup", "mouseup", ...

How to send a dynamic URL parameter to a function in Next.js TypeScript without using implicit typing

When utilizing the useRouter function with a parameter of type string, the following error is encountered: Type 'string | string[] | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type & ...

Creating a new element in the DOM when a button is clicked using Angular 2+

Greetings! I am currently in the process of learning how to manipulate the DOM using Angular 2+ and my goal is to incorporate an Input field with type email when the click event is activated. Despite conducting some research via Google, I have been unable ...

Having issues with Fullcalendar's custom view called "vertical resource view" functioning improperly

I am currently using fullcalendar 4 with angular and I am trying to implement a custom view based on this example: https://fullcalendar.io/docs/v4/vertical-resource-custom-demo The view I require spans across 5 days (Monday to Friday) for just one resou ...

Looking to establish combinations in typescript? The answer lies in utilizing a discriminated union

I've been working with Typescript and I'm curious if it's possible to specify the valid combinations of input for a function. Below is a simplified version of the code: interface ActionType { type: string, payload: { count?: ...

Search for records in MySQL using Typeorm with the condition "column like %var%" to retrieve results containing the specified

Looking for a way to search in MySql using typeorm with the "column like" functionality. async findAll({ page, count, ...where }: CategorySelectFilter): Promise<Category[]> { return this.categoryRepository.find({ where, ...

Remove httpOnly cookies in Express

Can browser cookies with the attribute HttpOnly:true be deleted? Here is a snippet of my login endpoint: async login(@Ip() ipAddress, @Request() req, @Res() res: Response) { const auth = await this.basicAuthService.login(req.user, ipAddress); ...

Having difficulties viewing the sidemenu icon on Ionic 3, despite enabling the menu through MenuController

I am trying to show the sidemenu icon on my Home page, which users can access from the Add-Contract page. Even though I have enabled the sidemenu in home.ts using this.menu.enable(true);, the icon is not visible. However, I can still swipe and access the ...

How can I indicate separate paths for the identical dependencies listed in package.json?

Currently, I am in the process of working on an npm package that consists of an example directory designed to run and test the actual package. Within this example directory, I have re-integrated the parent package using "file:..". While this set ...

Conditional return type mistakes

I'm facing an issue with a function that takes a parameter "value" and is supposed to return 0 or 1 based on its true or false value. Check it out here. const f = <T extends boolean>(value: T): false extends T ? 0 : 1 => { if (value === ...

Unexpected token error on an optional property in Visual Studio Code

I encountered a problem with a project I cloned. Below is the code snippet created using this project: https://github.com/enuchi/React-Google-Apps-Script export interface Vehicle { wheels: number; insurance?: string; } export default class Car { whe ...

Reusing a lazy-loaded module across multiple applications

Currently, I am working on an enterprise Angular 2 application with numerous lazy loaded modules. A new project came up where I needed to reuse a module that was previously created for the main app. After researching online, the only solution I found was ...

Converting JSON data into TypeScript interface objects within an Angular 2 environment

I have a JSON dataset with the following structure: { "timestamp": 1467471622, "base": "USD", "rates": { "AED": 3.673027, "AFN": 68.475, "ALL": 123.095199, "AMD": 476.8075, "ANG": 1.78385, "AOA": 165.846832, "ARS": 15.05 ...

Utilizing TypeScript typing with the Express Request object

Encountering an issue with Typescript typings involving the Express Request object. The project is comprised of 2 sub-projects, the user-service and a common project containing reusable Errors and Middlewares. The common folder is added as a dependency in ...