Abazhenov / express-async-handler

Async Error Handling Middleware for Express
572 stars 39 forks source link

Updated TypeScript import #27

Closed telmotrooper closed 5 years ago

telmotrooper commented 5 years ago

I'm pretty sure somewhere along the way you guys changed how the middleware is exported and your old TypeScript import syntax no longer works. I updated the README file with the import that works with the current version (as that is what has worked in my current project).

It might be a relevant that I'm on (current) TypeScript 3.1.6.

Abazhenov commented 5 years ago

Thanks for the PR, I'm also on typescript 3.1.6 and I'm actually not able to use import asyncHandler from 'express-async-handler'. Perhaps a setting in your tsconfig is preventing you from using import * as asyncHandler from 'express-async-handler'?

fiznool commented 5 years ago

I believe you need the allowSyntheticDefaultImports or esModuleInterop flags to be set to true in the tsconfig.json file to support the following syntax:

import asyncHandler from 'express-async-handler'

Otherwise, you have to use this:

import * as asyncHandler from 'express-async-handler'
Abazhenov commented 5 years ago

Thanks!