microsoft / microsoft/TypeScript

Duplicated files do not check unused @ts-expect-error properly

Open
#52,616 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs More Info
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Bug Report

🔎 Search Terms

redirectInfo, ts-expect-error

🕗 Version & Regression Information

Tested on 4.3.2, 4.9.5, and next (5.0.0-dev.20230204).

⏯ Playground Link

Reproduction: https://github.com/lamnhh/ts-expect-error-issue

💻 Code

There're 3 packages:

  • package-a:
// @ts-expect-error global
export const SOMETHING: number = global.testNumber;

Anything that has an @ts-expect-error directive will work.

  • a package-b that imports package-a
  • anothe package-c that imports both package-a and package-b.

Install everything, then npm link package-b to use in package-c.

🙁 Actual behavior

Unused '@ts-expect-error' directive.

> typecheck
> tsc --noEmit

../package-b/node_modules/@lamnhh/package-a/index.ts:1:1 - error TS2578: Unused '@ts-expect-error' directive.

1 // @ts-expect-error global
  ~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error in ../package-b/node_modules/@lamnhh/package-a/index.ts:1
🙂 Expected behavior

tsc in package-c passes with no error.

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 the reproduction repository at https://github.com/lamnhh/ts-expect-error-issue. Install the three packages, link package-b into package-c, and run tsc --noEmit in package-c to reproduce the unused @ts-expect-error diagnostic from package-a. Done means package-c type-checks without that diagnostic while the directive remains valid in package-a.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.