Cannot find declaration file for 'autobind-decorator' in typescript

Viewed 805

I am using Typescript and I want to import 'autobind-decorator' package inside project but ı stuck here.

I am getting this error line while compiling:

cannot find declaration file for 'autobind-decorator'. Implicitly has an 'any' type

I also tried @types/autobind-decorator npm package, but it didn't work. Is there any option to get rid of this compile error ?

Here is my tsconfig:

{
    "version": "2.1.5",
    "compilerOptions": {
        "module": "commonjs",
        "lib": ["es2015", "es2016", "dom"],
        "sourceMap": true,
        "noImplicitAny": true,
        "target": "es6",
        "jsx": "react",
        "skipLibCheck": true,
        "experimentalDecorators": true
    },
    "include": [
      "./packages/ld-web/src/**/*"
    ],
    "exclude": [
        "**/node_modules",
        "**/*.d.ts"
    ]
}

import :

import * as autobind from "autobind-decorator";

2 Answers

This worked, not using import at all:

const { autobind } = require('autobind-decorator');

I still had errors at runtime, so I read the doc again

https://www.npmjs.com/package/autobind-decorator

and used

const { boundMethod } = require('autobind-decorator');

that works,

I tried again using import and it failed.

Related