microsoft / microsoft/TypeScript

Type definitions overshadowing

Open
#37,316 14 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: Module Resolution
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.8.3

(also tried 3.9.0-dev.20200310)

Search Terms:
"Module '"immutable"' has no exported member"

Code

(not self contained)

import { hash } from "immutable";

export function test(): number {
    return hash(1);
}

Actual behavior:

src/index.ts:1:10 - error TS2305: Module '"immutable"' has no exported member 'hash'.

1 import { hash } from "immutable";
           ~~~~

even though
grep "export function hash" node_modules/immutable/dist/immutable.d.ts
reveals
export function hash(value: any): number;

Because it uses type definitions in
node_modules/@types/draft-js/node_modules/immutable/dist/immutable.d.ts
instead of
node_modules/immutable/dist/immutable.d.ts

Demo:

sadly I did not find any way to put it in a playground, in any case:
https://gitlab.com/rawieo/issue_demo_1

Related Issues:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/index.ts and compare the declarations in node_modules/immutable/dist/immutable.d.ts and node_modules/@types/draft-js/node_modules/immutable/dist/immutable.d.ts. Reproduce the import with TypeScript 3.8.3 or the noted nightly version, then trace module resolution to understand why the nested definitions are selected. Done means the valid hash export resolves without TS2305.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.