简体   繁体   中英

How can I import an external library without creating a custom .d.ts file OR turning noimplicitany off for my entire project?

Simple question - every time I import a new npm library that doesn't have a .d.ts file, I am creating a stub .d.ts file with lots of lines like this, just to compile:

function SomeFunctionINeed(...args: any[]): any

We love TS but this is our biggest hang-up right now. How can I import libraries and allow implicit any , without allowing implicit any for my entire project?

To keep the benefit of noImplicityAny while avoiding this, you can do:

declare module '*';

Create this file and add it to your tsconfig.json. eg:

// custom-typings/any-modules.d.ts
declare module '*';

// tsconfig.json
{
  "include": [
    "custom-typings"
  ]
}

Original discussion: https://github.com/Microsoft/TypeScript/issues/13348

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM