I'm facing an issue with providing TypeScript type definitions for a JavaScript library. The library itself is written in TypeScript and transpiled by Babel, although this detail shouldn't affect the outcome.
The problem lies in the fact that neither Intellij Idea nor ts-node
seem to pick up the type definitions.
Here are the relevant configurations and files of the library:
package.json
...
"main": "build/index.js",
"types": "build/index.d.ts",
"files": [
"build"
],
...
build/index.js
exports.Foo = {
bar: () => 'hello'
}
build/index.d.ts
export interface Foo {
bar: () => string
}
When using the type in TypeScript code, I encounter an error.
import { Foo } from 'apister'
Foo.bar()
// error TS2693: 'Foo' only refers to a type, but is being used as a value here.
Why aren't the type definitions being recognized?