Skip to content

Typescript node module can't find index.d.ts #2

@asciibits

Description

@asciibits

I am writing a TypeScript node module, and getting the following error when using @randomorg/core:

src/util/random.ts:1:31 - error TS7016: Could not find a declaration file for module '@randomorg/core'. '/home/lsanderson/src/minesweeper/node_modules/@randomorg/core/lib/esm/index.js' implicitly has an 'any' type.
  There are types at '/home/lsanderson/src/minesweeper/node_modules/@randomorg/core/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@randomorg/core' library may need to update its package.json or typings.

1 import {RandomOrgClient} from '@randomorg/core';
                                ~~~~~~~~~~~~~~~~~


Found 1 error in src/util/random.ts:1

I can fix this locally by explicitly adding index.d.ts into your package.json, like so:

{
  ...
  "types": "./types/index.d.ts",
  "typings": "./types/index.d.ts",
  "exports": {
    "require": "./lib/index.js",
    "import": "./lib/esm/index.js",
    "types": "./types/index.d.ts"
  },
  ...
}

If you agree this is a good solution, can you please add it? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions