Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript errors in external npm dependencies

Tags:

typescript

I have a tsconfig.json file which excludes:

"exclude": [
  "node_modules",
  "**/*-test.ts",
  "typings/*",
  "**/*.d.ts"
]

And yet in my attempts to transpile and lint I get the following error:

node_modules/aws-sdk/lib/request.d.ts(166,16): error TS2304: Cannot find name 'Promise'.

Does this make sense? I thought any errors within external dependencies should be excluded based on the above exclude.

p.s. the code -- including 3rd party deps -- works fine

like image 222
ken Avatar asked Oct 28 '25 12:10

ken


2 Answers

The exclude part tells the compiler which files/folders not to compile, but if a file that is being compiled is using a file in that is in the excluded list it will still be compiled, or as it states in the docs:

Any files that are referenced by files included via the "files" or "include" properties are also included. Similarly, if a file B.ts is referenced by another file A.ts, then B.ts cannot be excluded unless the referencing file A.ts is also specified in the "exclude" list.

If you are using a library that uses Promise then you better target es6 which should make this error disappear, but if you prefer not to then you can use the --skipLibCheck compiler option which:

Skip type checking of all declaration files (*.d.ts)


Edit

In the aws-sdk-js github readme file, in the Usage with TypeScript section under Pre-requisites it clearly states:

Your tsconfig.json or jsconfig.json includes 'dom' and 'es2015.promise' under compilerOptions.lib

like image 152
Nitzan Tomer Avatar answered Oct 31 '25 02:10

Nitzan Tomer


Try to add following code to tsconfig.json:

"compilerOptions": {
        "lib": [
          "es5",
          "es2015.promise"
        ]
      }
like image 26
Yury Glushkov Avatar answered Oct 31 '25 03:10

Yury Glushkov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!