Skip to content

Typescript generates invalid typedefs on incremental builds omitting importsΒ #51548

Closed
@Gozala

Description

@Gozala

Bug Report

πŸ”Ž Search Terms

  • import omit
  • invalid typedef

πŸ•— Version & Regression Information

Not sure when does it start but I discovered with 4.8.4 and still seems to occur with 4.9.3 and 5.0.0-dev.20221116

⏯ Playground Link

This can not be reproduced on playground as it requires multiple files. Instead I've created a repo with all the files
https://github.com/Gozala/ts-import-omit-bug

πŸ’» Code

bug.js
import * as B from "./box.js"
import * as W from "./wrap.js"

/**
 * @template C
 * @param {C} source
 * @returns {W.Wrap<C>}
 */
const wrap = source => {
  throw source
}

/**
 * @returns {B.Box<number>}
 */
const box = (n = 0) => ({ unbox: () => n })

export const bug = wrap({ n: box(1) })

box.ts

export interface Box<T> {
  unbox(): T
}

wrap.ts

export type Wrap<C> = {
  [K in keyof C]: { wrapped: C[K] }
}

πŸ™ Actual behavior

On incremental build TS generates invalid bug.d.ts file, which seems to omit B import.

export const bug: W.Wrap<{
    n: B.Box<number>;
}>;
import * as W from "./wrap.js";

E.g you could trigger incremental build by running npm test in linked repo or by running following command

tsc --build && echo \"\\nexport let a = 1\" >> ./src/bug.js && tsc --bulid

πŸ™‚ Expected behavior

It should always produce correct typedefs like

export const bug: W.Wrap<{
    n: B.Box<number>;
}>;
import * as B from "./box.js";
import * as W from "./wrap.js";

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions