Coder Social home page Coder Social logo

typescript-babel-starter's Introduction

TypeScript-Babel-Starter

What is this?

This is a small sample repository that uses Babel to transform TypeScript to plain JavaScript, and uses TypeScript for type-checking. This README will also explain step-by-step how you can set up this repository so you can understand how each component fits together.

For simplicity, we've used babel-cli with a bare-bones TypeScript setup, but we'll also demonstrate integration with JSX/React, as well as adding bundlers into the mix. Specifically, we'll show off integration with Webpack for if you're deploying an application, and Rollup for if you're producing a library.

How do I use it?

Building the repo

npm run build

Type-checking the repo

npm run type-check

And to run in --watch mode:

npm run type-check:watch

How would I set this up myself?

Install your dependencies

Either run the following:

npm install --save-dev typescript @babel/core @babel/cli @babel/plugin-proposal-class-properties @babel/preset-env @babel/preset-typescript

or make sure that you add the appropriate "devDependencies" entries to your package.json and run npm install:

"devDependencies": {
    "@babel/cli": "^7.8.3",
    "@babel/core": "^7.8.3",
    "@babel/plugin-proposal-class-properties": "^7.8.3",
    "@babel/preset-env": "^7.8.3",
    "@babel/preset-typescript": "^7.8.3",
    "typescript": "^3.7.5"
}

Create your tsconfig.json

Then run

tsc --init --declaration --allowSyntheticDefaultImports --target esnext --outDir lib

Note: TypeScript also provides a --declarationDir option which specifies an output directory for generated declaration files (.d.ts files). For our uses where --emitDeclarationOnly is turned on, --outDir works equivalently.

Create your .babelrc

Then copy the .babelrc in this repo, or the below:

{
    "presets": [
      "@babel/preset-env",
      "@babel/preset-typescript"
    ],
    "plugins": [
      "@babel/plugin-proposal-class-properties"
    ]
}

Set up your build tasks

Add the following to the "scripts" section of your package.json

"scripts": {
    "type-check": "tsc --noEmit",
    "type-check:watch": "npm run type-check -- --watch",
    "build": "npm run build:types && npm run build:js",
    "build:types": "tsc --emitDeclarationOnly",
    "build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline"
}

How do I change it?

Using JSX (and React)

Full example available here

Install your dependencies

Install the @babel/preset-react package as well as React, ReactDOM, and their respective type declarations

npm install --save react react-dom @types/react @types/react-dom
npm install --save-dev @babel/preset-react

Update .babelrc

Then add "@babel/react" as one of the presets in your .babelrc.

Update tsconfig.json

Update your tsconfig.json to set "jsx" to "react".

Use a .tsx file

Make sure that any files that contain JSX use the .tsx extension. To get going quickly, just rename src/index.ts to src/index.tsx, and add the following lines to the bottom:

import React from 'react';
export let z = <div>Hello world!</div>;

Using Webpack

Full example available here

Install your dependencies

npm install --save-dev webpack webpack-cli babel-loader

Create a webpack.config.js

Create a webpack.config.js at the root of this project with the following contents:

var path = require('path');

module.exports = {
    // Change to your "entry-point".
    entry: './src/index',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'app.bundle.js'
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js', '.json']
    },
    module: {
        rules: [{
            // Include ts, tsx, js, and jsx files.
            test: /\.(ts|js)x?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
        }],
    }
};

Create a build task

Add

"bundle": "webpack"

to the scripts section in your package.json.

Run the build task

npm run bundle

Using Rollup

Full example available here

Install your dependencies

npm install --save-dev rollup @rollup/plugin-babel @rollup/plugin-node-resolve @rollup/plugin-commonjs

Create a rollup.config.js

Create a rollup.config.js at the root of this project with the following contents:

import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import pkg from './package.json';

const extensions = [
  '.js', '.jsx', '.ts', '.tsx',
];

const name = 'RollupTypeScriptBabel';

export default {
  input: './src/index.ts',

  // Specify here external modules which you don't want to include in your bundle (for instance: 'lodash', 'moment' etc.)
  // https://rollupjs.org/guide/en#external-e-external
  external: [],

  plugins: [
    // Allows node_modules resolution
    resolve({ extensions }),

    // Allow bundling cjs modules. Rollup doesn't understand cjs
    commonjs(),

    // Compile TypeScript/JavaScript files
    babel({ extensions, include: ['src/**/*'] }),
  ],

  output: [{
    file: pkg.main,
    format: 'cjs',
  }, {
    file: pkg.module,
    format: 'es',
  }, {
    file: pkg.browser,
    format: 'iife',
    name,

    // https://rollupjs.org/guide/en#output-globals-g-globals
    globals: {},
  }],
};

Create a build task

Add

"bundle": "rollup -c"

to the scripts section in your package.json.

Run the build task

npm run bundle

Using NodeJS

Full example available here

Install your dependencies

npm install --save-dev @babel/core @babel/node @babel/plugin-proposal-class-properties @babel/preset-env @babel/preset-typescript typescript

Create a start task

Add

"start": "babel-node -x \".ts\" src/index.ts"

to the scripts section in your package.json.

Run the start task

npm run start

typescript-babel-starter's People

Contributors

a-tarasyuk avatar balloob avatar capaj avatar corydeppen avatar danielrosenwasser avatar dependabot[bot] avatar drubetti avatar exkazuu avatar it-efrem avatar matijs avatar ore4444 avatar orta avatar rcasto avatar ryancavanaugh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typescript-babel-starter's Issues

No need to create tsconfig.json

Create your tsconfig.json

Then run

tsc --init --declaration --allowSyntheticDefaultImports --target esnext --outDir lib

This command also generates tsconfig.json. If the file already exists there is an error message:

error TS5054: A 'tsconfig.json' file is already defined at: '/Volumes/DanBackup/Websites/wpdtrt-plugin-boilerplate/tsconfig.json'.

Webpack build does not run due to terser-webpack-plugin dependency

Thanks

First off great starting guide! Decided I wanted to learn Typescript and your starter guide has helped a lot. Just so you are aware when using the additional webpack configure the project will not build. Im not sure if you would like a PR with the fix to this issue as it seems the maintainers are already working on solving this on there end but if so I would be happy to help.

Problem

terser-webpack-plugin crashes when Webpack is ran.

Logs

Starting type checking service...
Using 1 worker with 2048MB memory limit
Hash: 8deabb4a8938f47197c2
Version: webpack 4.28.3
Time: 498ms
Built at: 2019-02-02 21:17:59
 1 asset
Entrypoint main = bundle.js
[0] ./src/index.ts 1.66 KiB {0} [built]

ERROR in bundle.js from Terser
TypeError: Cannot read property 'minify' of undefined
    at minify (/home/jacob/Development/personal/content-tweeter/node_modules/terser-webpack-plugin/dist/minify.js:175:23)
    at module.exports (/home/jacob/Development/personal/content-tweeter/node_modules/terser-webpack-plugin/dist/worker.js:13:40)
    at handle (/home/jacob/Development/personal/content-tweeter/node_modules/worker-farm/lib/child/index.js:44:8)
    at process.<anonymous> (/home/jacob/Development/personal/content-tweeter/node_modules/worker-farm/lib/child/index.js:51:3)
    at emitTwo (events.js:126:13)
    at process.emit (events.js:214:7)
    at emit (internal/child_process.js:772:12)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build:js: `webpack --mode=production`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] build:js script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

More Info

This has already been reported to the maintainers webpack-contrib/terser-webpack-plugin#67

And is explained in webpack-contrib/terser-webpack-plugin#66

Fix

As stated in Issue 66 add the following to your package.json

  "resolutions": {
    "terser": "3.14.1"
  }

Using typescript babel to transition from flow

What would be the recommended practice for switching from flow to typescript?

We (nteract) have a large code base (as a lerna monorepo) written with flow and this seems like a good way for us to transition individual packages to typescript, since everything is currently babel backed in our code base.

How did source map generate?

I intend to use this solutions to generate code in my project, including js and ts files,
but I want to generate sourceMap of ts files,
how can I achieve that in this example?

README

Hey,

In the README should it be this ๐Ÿ‘‡

{
    "presets": [
        "@babel/preset-env",
        "@babel/preset-typescript"
    ],
...
}

rather than this ๐Ÿ‘‡

{
    "presets": [
        "@babel/env",
        "@babel/typescript"
    ],
...
}

Debugging

Hello.
I have been struggling lately to debug this project, I had also added webpack to it like the README file suggested.
I have spent hours trying different setups of configuration to the launch.json file with no luck.
I had tried so many different combinations that I am not sure what to post...
Have someone managed to get a debugging session working? If so I'd love to see it.
Thanks

error TS2688: Cannot find type definition file for 'babel__core'.

> [email protected] build:types /Users/heweipeng/byted/TypeScript-Babel-Starter
> tsc --emitDeclarationOnly

error TS2688: Cannot find type definition file for 'babel__core'.

error TS2688: Cannot find type definition file for 'babel__template'.


Found 2 errors.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build:types: `tsc --emitDeclarationOnly`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build:types script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/heweipeng/.npm/_logs/2020-01-16T07_29_50_627Z-debug.log
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Update Dependency

What cycle are the npm dependent versions of the document updated?

Add Why to the README

Since TypeScript can already transpile even newer ECMAScript features, it may make sense to add a section explaining why use Babel alongside as well.

Import a .ts file from src/index.ts

Please extend the. example by creatinng a file src/b.ts, importing that file from src/index.ts and showing how this works in webpack, rollup and tsc. I cannot get this running.

Polyfills for example Promise is not included automatically?

Hello, I tried the TypeScript-Babel-Starter setup. For some reason polyfills are not automatically included.

Am I missing something here? I thought that is the point of using babel.

Example:

function main() {
    return new Promise((resolve) => resolve("yes!"));
}

main();

Result:

function main() {
  return new Promise(function (resolve) {
    return resolve("yes!");
  });
}

main();

I haven't changed the file .babelrc / .tsconfig.

But also when adding in .babelrc the following preset it won't use Promise polyfill.

    [
      "@babel/preset-env",
      {
        "useBuiltIns": "entry"
      }
    ]

(also included a browserslist with IE11)

How would this work with project references?

Let's say I have a monorepo with packages/app and packages/lib. In the tsc world, I'd create app/tsconfig.json with this:

{
  "references": [
    { "path": "../lib" }
  ]
}

And when transpiling, tsc -b would check if source files in lib changed and re-build them if necessary.

If Babel is responsible for transpiling, will it pick up changes in lib? Does it read tsconfig.json configuration about project references?

regeneratorRuntime is not defined

Hi there.

Do you guys have an option on how to deal with the regeneratorRuntime is not defined issue?

I updates your index.ts and added the following method into the C class:

async metodo() {
  return "ok";
}

After building it and trying to invoke the transpiled code using node ./lib/index I got the following error:

$ node
> require("./lib/index")
ReferenceError: regeneratorRuntime is not defined
    at /Users/adilson/dev/TypeScript-Babel-Starter/lib/index.js:46:7
    at /Users/adilson/dev/TypeScript-Babel-Starter/lib/index.js:64:6
> 

That's because of this part of the generated code that requires regeneratorRuntime to work:

_createClass(C, [{
  key: "metodo",
  value: function () {
    var _metodo = _asyncToGenerator(
    /*#__PURE__*/
    regeneratorRuntime.mark(function _callee() {
      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              return _context.abrupt("return", "ok");

            case 1:
            case "end":
              return _context.stop();
          }
        }
      }, _callee, this);
    }));

    return function metodo() {
      return _metodo.apply(this, arguments);
    };
  }()
}]);

All the post I saw so far mention those two options:

  • @babel/plugin-transform-regenerator which I could not manage to get it working

  • to add @babel/polyfill that actually works but it is a terrible option when coding a new lib as there is no central import point, making the require to happen on each file

Do you have any tips on that?

Thanks!

When use with Webpack+React+Babel-loader get error: You gave us a visitor for the node type "TSDeclareFunction" but it's not a valid type

I use to you description to migrate webpack+Babel+React app to typescript but get the error:

> Executing task: npm run start <


> [email protected] start d:\Projects\react-bootstrap-project
> webpack-dev-server --mode development --config ./config/webpack.config.babel.js

babel-preset-env: `DEBUG` option

Using targets:
{
  "node": "10.5"
}

Modules transform: commonjs

Using plugins:
d:\Projects\react-bootstrap-project\node_modules\babel-core\lib\transformation\file\options\option-manager.js:328
        throw e;
        ^

Error: You gave us a visitor for the node type "TSDeclareFunction" but it's not a valid type (While processing preset: "d:\\Projects\\react-bootstrap-project\\node_modules\\babel-preset-typescript\\lib\\index.js")
    at verify (d:\Projects\react-bootstrap-project\node_modules\babel-traverse\lib\visitors.js:196:13)
    at Function.explode (d:\Projects\react-bootstrap-project\node_modules\babel-traverse\lib\visitors.js:72:3)
    at Plugin.normaliseVisitor (d:\Projects\react-bootstrap-project\node_modules\babel-core\lib\transformation\plugin.js:155:29)
    at new Plugin (d:\Projects\react-bootstrap-project\node_modules\babel-core\lib\transformation\plugin.js:66:27)
    at Function.memoisePluginContainer (d:\Projects\react-bootstrap-project\node_modules\babel-core\lib\transformation\file\options\option-manager.js:119:21)
    at Function.normalisePlugin (d:\Projects\react-bootstrap-project\node_modules\babel-core\lib\transformation\file\options\option-manager.js:146:32)
    at d:\Projects\react-bootstrap-project\node_modules\babel-core\lib\transformation\file\options\option-manager.js:184:30
    at Array.map (<anonymous>)
    at Function.normalisePlugins (d:\Projects\react-bootstrap-project\node_modules\babel-core\lib\transformation\file\options\option-manager.js:158:20)
    at OptionManager.mergeOptions (d:\Projects\react-bootstrap-project\node_modules\babel-core\lib\transformation\file\options\option-manager.js:234:36)

Here is my repository

Module parse failed: Unexpected token (54:52)

    "react": "^18.2.0",
    "next": "^12.2.5",
    "react-dom": "^18.2.0",
    "rollup": "^2.79.0",
    "rollup-plugin-ts": "^3.0.2",
    "ts-loader": "^9.3.1",
    "ts-node": "^10.9.1",
    "typescript": "^4.7.4",
    "webpack": "^5.74.0",
    "webpack-cli": "^4.10.0"

webpack.config.js:

import path from 'path';

module.exports = {
    mode: "development",
    // Change to your "entry-point".
    entry: './index',
    output: {
        path: path.resolve(__dirname, '.next'),
        filename: 'app.bundle.js'
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
    },
    module: {
        rules: [
        {
            test: /\.(css)$/,
            include: [/stylesheets/, /node_modules/],
            use: [
                'css-loader',
            ],
        },
        {
            test: /\.css$/,
            exclude: [/stylesheets/, /node_modules/],
            use: [
                'css-loader?sourceMap&modules,localIdentName=[local]-[hash:base64]',
            ],
        },            
        {
            // Include ts, tsx, js, and jsx files.
            test: /\.(ts|js)x?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
        }],
    }
};

.babelrc:

{
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react",
      "@babel/preset-typescript"
    ],
    "plugins": [
      "@babel/plugin-proposal-class-properties"
    ]
}

tsconfig.json:

{
  "extends": "../../tsconfig.json",
  "exclude": [
    "node_modules",
    "build"
  ],
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.js",
    "**/*.tsx",
    "**/*.json"
  ],
  "node-option": [
    "experimental-specifier-resolution=node",
    "loader=ts-node/esm"
  ],
  "extensions": [
    "ts",
    "tsx"
  ],
  "compilerOptions": {
    "baseUrl": ".",
    "outDir": "build/",
    "incremental": true,
    "target": "es2022",
    "lib": [
      "dom",
      "dom.iterable",
      "es2022"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "plugins": [
      {
        "name": "@rollup/plugin-typescript"
      },
      {
        "name": "@rollup/plugin-json"
      }
    ],
    "noEmit": true,
    "jsx": "preserve"
  },
  "references": [
    {
      "path": "../api"
    }
  ]
}

next.config.mjs:

export default {
  swcMinify: true,
  experimental: {
    forceSwcTransforms: true,
    swcTraceProfiling: true,
  },
  output: 'standalone',
};

next build errors:

../web/src/views/Dashboard/Bids/BidDetailsDescriptionTable.tsx
Module parse failed: Unexpected token (58:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|   const { subtotal, shipping } = pricing || {}
|   return (
>     <Root>
|       <Hidden mdDown>
|         <Table className={classes.tableBody}>

../web/src/views/Dashboard/Bids/QuotationDetails/QuotationSlip.tsx
Module parse failed: Unexpected token (65:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|   const { sellerSignature, sellerSigneeName, sellerSigneeDesignation, quotationTimeStamp } = quotationBid || {}
|   return (
>     <Root className={classes.boxWrap}>
|       <SharedSlipDetails titleType="Quotation" bidStatusTimeStamp={QUOTATION_TIME_STAMP} quotationBid={quotationBid} />
|       <BidDetailsDescriptionTable quotationBid={quotationBid} />

../web/src/views/Dashboard/Bids/SharedSlipDetails.tsx
Module parse failed: Unexpected token (69:4)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
|   return (
>     <Root>
|       <Box display="flex">
|         <img src="/images/kyberlife-bid-form-logo.png" alt="logo" className={classes.imgSize} />

../web/src/views/Dashboard/Messages/Messages.tsx
Module parse failed: Unexpected token (194:27)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
|   // Getters
>   const getInitialChats = (): ChatInterface[] => {
|     const isNewChatAlreadyExists =
|       hasNewChat && prevChats?.find((prevChat) => prevChat.participantIDs.includes(query.sellerID as string))

../web/src/views/Dashboard/Messages/utils.ts
Module parse failed: Unexpected token (9:42)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import { SellerInterface } from '@app/api/src/modules/Seller/model/Seller'
| 
> export const getUnreadMessageCount = (chat: ChatInterface, userID: string): number => {
|   const unReadMessages =
|     chat?.messages?.filter(({ isReadIDs }) => !isReadIDs || !isReadIDs.includes(userID))?.length || 0

decorators support

Is there any way to enable Typescript decorators support? "@babel/plugin-proposal-decorators" doesn't seem to work

update babel config

@babel/plugin-proposal-class-properties can be removed from .babelrc because it was included in @babel/preset-env, in ES2022, and update packages and README.md.

tsc --emitDeclarationOnly results in many errors in node_modules/@types files

โœ— tsc --version
Version 3.3.4000

โœ— npm run build 
> npm run build:types && npm run build:cjs && npm run webpack && npm run nessie-stats


> @company/[email protected] build:types /Users/jcol00000/Documents/work/orders
> tsc --emitDeclarationOnly

node_modules/@types/jest/index.d.ts:24:13 - error TS2300: Duplicate identifier 'beforeEach'.

24 declare var beforeEach: jest.Lifecycle;
               ~~~~~~~~~~

  node_modules/@types/mocha/index.d.ts:63:18
    63 declare function beforeEach(callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void;
                        ~~~~~~~~~~
    'beforeEach' was also declared here.
  node_modules/@types/mocha/index.d.ts:64:18
    64 declare function beforeEach(description: string, callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void;
                        ~~~~~~~~~~
    and here.

node_modules/@types/jest/index.d.ts:26:13 - error TS2300: Duplicate identifier 'afterEach'.

26 declare var afterEach: jest.Lifecycle;
               ~~~~~~~~~

  node_modules/@types/mocha/index.d.ts:65:18
    65 declare function afterEach(callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void;
                        ~~~~~~~~~
    'afterEach' was also declared here.
  node_modules/@types/mocha/index.d.ts:66:18
    66 declare function afterEach(description: string, callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void;
                        ~~~~~~~~~
    and here.

node_modules/@types/jquery/index.d.ts:6107:66 - error TS2344: Type '"timeout" | "onreadystatechange" | "responseType" | "withCredentials" | "msCaching"' does not satisfy the constraint '"abort" | "open" | "timeout" | "response" | "onreadystatechange" | "responseType" | "withCredentials" | "readyState" | "responseText" | "responseURL" | "responseXML" | "status" | ... 21 more ... | "dispatchEvent"'.
  Type '"msCaching"' is not assignable to type '"abort" | "open" | "timeout" | "response" | "onreadystatechange" | "responseType" | "withCredentials" | "readyState" | "responseText" | "responseURL" | "responseXML" | "status" | ... 21 more ... | "dispatchEvent"'.

6107         interface XHRFields extends Partial<Pick<XMLHttpRequest, 'onreadystatechange' | 'responseType' | 'timeout' | 'withCredentials' | 'msCaching'>> { }
                                                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@types/mocha/index.d.ts:36:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'describe' must be of type 'Describe', but here has type 'IContextDefinition'.

36 declare var describe: Mocha.IContextDefinition;
               ~~~~~~~~

node_modules/@types/mocha/index.d.ts:37:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'xdescribe' must be of type 'Describe', but here has type 'IContextDefinition'.

37 declare var xdescribe: Mocha.IContextDefinition;
               ~~~~~~~~~

node_modules/@types/mocha/index.d.ts:42:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'it' must be of type 'It', but here has type 'ITestDefinition'.

42 declare var it: Mocha.ITestDefinition;
               ~~

node_modules/@types/mocha/index.d.ts:43:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'xit' must be of type 'It', but here has type 'ITestDefinition'.

43 declare var xit: Mocha.ITestDefinition;
               ~~~

node_modules/@types/mocha/index.d.ts:45:13 - error TS2403: Subsequent variable declarations must have the same type.  Variable 'test' must be of type 'It', but here has type 'ITestDefinition'.

45 declare var test: Mocha.ITestDefinition;
               ~~~~

node_modules/@types/mocha/index.d.ts:63:18 - error TS2300: Duplicate identifier 'beforeEach'.

63 declare function beforeEach(callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void;
                    ~~~~~~~~~~

  node_modules/@types/jest/index.d.ts:24:13
    24 declare var beforeEach: jest.Lifecycle;
                   ~~~~~~~~~~
    'beforeEach' was also declared here.

node_modules/@types/mocha/index.d.ts:64:18 - error TS2300: Duplicate identifier 'beforeEach'.

64 declare function beforeEach(description: string, callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void;
                    ~~~~~~~~~~

  node_modules/@types/jest/index.d.ts:24:13
    24 declare var beforeEach: jest.Lifecycle;
                   ~~~~~~~~~~
    'beforeEach' was also declared here.

node_modules/@types/mocha/index.d.ts:65:18 - error TS2300: Duplicate identifier 'afterEach'.

65 declare function afterEach(callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void;
                    ~~~~~~~~~

  node_modules/@types/jest/index.d.ts:26:13
    26 declare var afterEach: jest.Lifecycle;
                   ~~~~~~~~~
    'afterEach' was also declared here.

node_modules/@types/mocha/index.d.ts:66:18 - error TS2300: Duplicate identifier 'afterEach'.

66 declare function afterEach(description: string, callback: (this: Mocha.IBeforeAndAfterContext, done: MochaDone) => any): void;
                    ~~~~~~~~~

  node_modules/@types/jest/index.d.ts:26:13
    26 declare var afterEach: jest.Lifecycle;
                   ~~~~~~~~~
    'afterEach' was also declared here.


Found 12 errors.

tsconfig.json:

  "compilerOptions": {
    /* Basic Options */
    "target": "es5",                          /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
    "module": "commonjs",                     /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    "jsx": "react",                     /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
    "composite": true,                     /* Enable project compilation */
    "removeComments": true,                /* Do not emit comments to output. */
    "strict": true,                           /* Enable all strict type-checking options. */
    "esModuleInterop": true                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
}
}

I'm adapting TS into an existing project that builds using Babel - just to see if we can get any benefit from TS. Definitely not a promising start.

Recreating tsconfig with tsc --init --declaration --allowSyntheticDefaultImports --target esnext --outDir lib was not any different.

Typescript errors don't break build

When using @babel/preset-typescript with babel-loader (webpack), a typescript error does not break the build. It compiles no matter what which renders typescript useless. When using just webpack and ts-loader I get the desired result of seeing errors in the terminal and a broken build when there is a typescript issue. Is this the intended behavior using typescript and babel in webpack ?

Optional chaining does not work

image

1st attempt: change tsconfig.json to

{
  "compilerOptions": {
     "target": "ES2015",
     "module": "ESNext",
  }
}

2nd attempt: typescript 3.8.3 also error

What is the configuration for using Optional chaining & Null coalescing?

Supporting eslint

ESLint would expect ESTree compliant input to accurately report ESLint errors. so parser used is typescript-eslint-parser.

The eslint command works fine but VSCode stops showing ESLint errors with following config:

{
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended"
    ],
    "env": {
        "browser": true
    },
    "parser": "typescript-eslint-parser",
    "parserOptions": {
        "ecmaVersion": 6,
        "ecmaFeatures": {
            "jsx": true
        },
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "linebreak-style":"off"
    },
    "settings": {
      "import/resolver": "webpack"
    },
    "overrides": [
        {
            "files": ["**/*.ts", "**/*.tsx"],
            "parser": "typescript-eslint-parser",
            "rules": {
              "no-undef": "off",
              "react/prop-types": "off"
            }
        }
    ]
}

Repo for reproducibility: https://github.com/chetnashah/formik-app

jsx option should be "preserve"

In the "Using JSX" section there is this instruction:

Update your tsconfig.json to set "jsx" to "react".

I think that the right value should be "preserve", since the TypeScript documentation says that

The preserve mode will keep the JSX as part of the output to be further consumed by another transform step (e.g. Babel)

If I understand correctly the JSX transformation is not performed by @babel/preset-typescript but by @babel/preset-react, so what is the point to declare a JSX transformation in the tsconfig? Setting preserve can also be useful for supporting the new JSX transform: in the tsconfig we can specify always preserve and let babel decide how to transform the JSX code

Error: Cannot find module 'koa'

  1. I have cloned this demo . after installing koa,koa-router etc, I got an error. Here is my index.ts file
import Koa from "koa"
import Router from "koa-router"
import logger from "koa-logger"
import json from "koa-json"

const app = new Koa()
const router = new Router()

router.get("/",async(ctx: any,next: any)=>{
    ctx.body = {
        meg:"Hello world"
    }
    await next
})

app.use(logger())
app.use(json())
app.use(router.routes()).use(router.allowedMethods())

app.listen(3000,()=>console.log("app is running at 3000"))

Here is my package.json

{
  "name": "babel-typescript-sample",
  "version": "0.7.2",
  "license": "MIT",
  "scripts": {
    "type-check": "tsc --noEmit",
    "type-check:watch": "npm run type-check -- --watch",
    "build": "npm run build:types && npm run build:js",
    "build:types": "tsc --emitDeclarationOnly",
    "build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline"
  },
  "devDependencies": {
    "@babel/cli": "^7.8.3",
    "@babel/core": "^7.8.3",
    "@babel/plugin-proposal-class-properties": "^7.8.3",
    "@babel/preset-env": "^7.8.3",
    "@babel/preset-typescript": "^7.8.3",
    "@types/koa": "^2.11.3",
    "typescript": "^3.7.5"
  },
  "dependencies": {
    "koa": "^2.11.0",
    "koa-bodyparser": "^4.3.0",
    "koa-json": "^2.0.2",
    "koa-logger": "^3.2.1",
    "koa-router": "^8.0.8"
  }
}

my file structure loos like:

/-------
  -lib
    -index.js
    -index.d.ts
  -node_modules
  -src
    -index.ts
  1. Actually,before this ,when I run npm run build,I got error src/index.ts:2:20 - error TS2307: Cannot find module 'koa-router'. I write 'koa-router.d.ts' myself, but I don't think it's a great idea, How do you guys resolve?

Got errors when installing React

run npm install --save react react-dom @types/react @types/react-dom Got errors:

npm WARN lifecycle The node binary used for scripts is /Users/crokobit/.asdf/shims/node but npm is using /Users/crokobit/.asdf/installs/nodejs/12.10.0/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.

> [email protected] install /Users/crokobit/Office/TypeScript-Babel-Starter/node_modules/fsevents
> node install

node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.2.7/fse-v1.2.7-node-v72-darwin-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v72 ABI, unknown) (falling back to source compile with node-gyp)
  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
In file included from ../fsevents.cc:6:
In file included from ../../nan/nan.h:2722:
../../nan/nan_object_wrap.h:24:25: error: no member named 'IsNearDeath' in 'Nan::Persistent<v8::Object, v8::NonCopyablePersistentTraits<v8::Object> >'
    assert(persistent().IsNearDeath());
           ~~~~~~~~~~~~ ^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/assert.h:93:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #e) : (void)0)
                        ^
In file included from ../fsevents.cc:6:
In file included from ../../nan/nan.h:2722:
../../nan/nan_object_wrap.h:127:26: error: no member named 'IsNearDeath' in 'Nan::Persistent<v8::Object, v8::NonCopyablePersistentTraits<v8::Object> >'
    assert(wrap->handle_.IsNearDeath());
           ~~~~~~~~~~~~~ ^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/assert.h:93:25: note: expanded from macro 'assert'
    (__builtin_expect(!(e), 0) ? __assert_rtn(__func__, __FILE__, __LINE__, #e) : (void)0)
                        ^
../fsevents.cc:43:32: error: no template named 'Handle' in namespace 'v8'
    static void Initialize(v8::Handle<v8::Object> exports);
                           ~~~~^
In file included from ../fsevents.cc:73:
../src/constants.cc:89:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagNone").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagNone));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:90:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagMustScanSubDirs").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagMustScanSubDirs));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:91:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagUserDropped").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagUserDropped));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:92:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagKernelDropped").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagKernelDropped));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:93:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagEventIdsWrapped").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagEventIdsWrapped));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:94:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagHistoryDone").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagHistoryDone));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:95:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagRootChanged").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagRootChanged));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:96:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagMount").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagMount));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:97:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagUnmount").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagUnmount));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:98:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagItemCreated").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagItemCreated));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:99:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagItemRemoved").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagItemRemoved));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:100:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagItemInodeMetaMod").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagItemInodeMetaMod));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:101:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagItemRenamed").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagItemRenamed));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:102:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagItemModified").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagItemModified));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:103:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagItemFinderInfoMod").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagItemFinderInfoMod));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:104:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagItemChangeOwner").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagItemChangeOwner));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:105:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagItemXattrMod").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagItemXattrMod));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:106:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagItemIsFile").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagItemIsFile));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:107:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagItemIsDir").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagItemIsDir));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
In file included from ../fsevents.cc:73:
../src/constants.cc:108:11: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
  object->Set(Nan::New<v8::String>("kFSEventStreamEventFlagItemIsSymlink").ToLocalChecked(), Nan::New<v8::Integer>(kFSEventStreamEventFlagItemIsSymlink));
          ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8.h:3371:3: note: 'Set' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version",
  ^
/Users/crokobit/Library/Caches/node-gyp/12.10.0/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
  declarator __attribute__((deprecated(message)))
                            ^
../fsevents.cc:76:16: error: variable has incomplete type 'void'
void FSEvents::Initialize(v8::Handle<v8::Object> exports) {
               ^
../fsevents.cc:76:31: error: no member named 'Handle' in namespace 'v8'
void FSEvents::Initialize(v8::Handle<v8::Object> exports) {
                          ~~~~^
../fsevents.cc:76:48: error: expected '(' for function-style cast or type construction
void FSEvents::Initialize(v8::Handle<v8::Object> exports) {
                                     ~~~~~~~~~~^
../fsevents.cc:76:50: error: use of undeclared identifier 'exports'
void FSEvents::Initialize(v8::Handle<v8::Object> exports) {
                                                 ^
../fsevents.cc:76:58: error: expected ';' after top level declarator
void FSEvents::Initialize(v8::Handle<v8::Object> exports) {
                                                         ^
                                                         ;
20 warnings and 8 errors generated.
make: *** [Release/obj.target/fse/fsevents.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/crokobit/.asdf/installs/nodejs/12.10.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:196:23)
gyp ERR! stack     at ChildProcess.emit (events.js:209:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 18.7.0
gyp ERR! command "/Users/crokobit/.asdf/installs/nodejs/12.10.0/bin/node" "/Users/crokobit/.asdf/installs/nodejs/12.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/Users/crokobit/Office/TypeScript-Babel-Starter/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64/fse.node" "--module_name=fse" "--module_path=/Users/crokobit/Office/TypeScript-Babel-Starter/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64" "--napi_version=4" "--node_abi_napi=napi"
gyp ERR! cwd /Users/crokobit/Office/TypeScript-Babel-Starter/node_modules/fsevents
gyp ERR! node -v v12.10.0
gyp ERR! node-gyp -v v5.0.3
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/Users/crokobit/.asdf/installs/nodejs/12.10.0/bin/node /Users/crokobit/.asdf/installs/nodejs/12.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/crokobit/Office/TypeScript-Babel-Starter/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64/fse.node --module_name=fse --module_path=/Users/crokobit/Office/TypeScript-Babel-Starter/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64 --napi_version=4 --node_abi_napi=napi' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/crokobit/Office/TypeScript-Babel-Starter/node_modules/fsevents/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:209:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
node-pre-gyp ERR! System Darwin 18.7.0
node-pre-gyp ERR! command "/Users/crokobit/.asdf/installs/nodejs/12.10.0/bin/node" "/Users/crokobit/Office/TypeScript-Babel-Starter/node_modules/fsevents/node_modules/node-pre-gyp/bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/crokobit/Office/TypeScript-Babel-Starter/node_modules/fsevents
node-pre-gyp ERR! node -v v12.10.0
node-pre-gyp ERR! node-pre-gyp -v v0.10.3
node-pre-gyp ERR! not ok
Failed to execute '/Users/crokobit/.asdf/installs/nodejs/12.10.0/bin/node /Users/crokobit/.asdf/installs/nodejs/12.10.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/crokobit/Office/TypeScript-Babel-Starter/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64/fse.node --module_name=fse --module_path=/Users/crokobit/Office/TypeScript-Babel-Starter/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64 --napi_version=4 --node_abi_napi=napi' (1)
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node install`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ [email protected]
+ @types/[email protected]
+ @types/[email protected]
+ [email protected]
added 3 packages from 23 contributors, removed 35 packages, updated 4 packages and audited 3673 packages in 8.729s
found 33 high severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details

Testing with Babel-Jest

This example is a great start towards equalizing the usage of TS and Flow for type checking and allowing the integration of TS into Babel projects ๐ŸŽ‰ Kudos ๐Ÿ‘

I am however having issues with integrating Jest tests into this setup. With TS I would normally use ts-jest, however now that the compilation is being handled by Babel I would think I would need babel-jest so I could run the tests against the Babel output and not the TSC output as I'll be deploying the Babel output, not TSC.

Are there plans to expand this example to include Babel-Jest or is that beyond the scope of this example? If so, has anyone tried this yet and have any pointers?

If this is the right place for the discussion I will update this issue with terminal logs etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.