microsoft / microsoft/TypeScript

TS 5.6 requires composite projects with noEmit to have fully accessible types, unlike 5.5

Open
#59,951 7 comments 3 reactions 1 assignee View on GitHub

@sheetalkamat is already working on this.

Since Sep 13, 2024.

Needs Investigation
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔎 Search Terms

TS2742, TS7056, TS9006, TS4058, TS4023, noEmit, composite, 5.6

🕗 Version & Regression Information
  • This changed between versions 5.5.4 and 5.6.2
⏯ Playground Link

https://github.com/Ambroos/ts-56-composite-project-noemit

💻 Code

file: Internal.ts

interface Internal {
    a: boolean,
}

export default function somethingInternal() {
    return {
        one: { a: true } as Internal,
    };
}

file: index.ts

import createInternal from "./Internal";
export const one = createInternal().one;

file: tsconfig.json

{
    "compilerOptions": {
        "composite": true,
        "noEmit": true,
        "strict": true,
    },
    "include": [
        "*.ts"
    ]
}
🙁 Actual behavior

In TS 5.6.2, run tsc and get error:

index.ts:3:14 - error TS4023: Exported variable 'one' has or is using name 'Internal' from external module "/Users/ambroos/Dev/ts-composite-5.6/Internal" but cannot be named.

3 export const one = createInternal().one;

This is the error in the sample project linked above (or created with the files from the code part). In our actual repo a large amount of new errors appeared that are related: TS2742, TS7056, TS9006, TS4058, TS4023.

🙂 Expected behavior

No errors, like 5.5.4 and older.

Additional information about the issue

This only happens in composite projects, even when not using --build. We have a large composite project, but the oldest parts of our code live in projects that don't emit since no-one is allowed to depend on them (they're apps that get built as-is).

In the past, when not emitting type declarations, it was OK to reference types that cannot be named, even in incremental compilation / composite projects. Now however it looks like because .tsbuildinfo is always generated, making code able to be emitted seems to have become required.

Maybe this is intentional, but it would be nice to still have some escape hatch for these types of composite project parts that don't actually need to emit declarations, they just need to be checked and transpiled.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.