microsoft / microsoft/TypeScript

Need an option for ignore error when emit declaration

Open
#54,305 8 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

Suggestion

🔍 noEmitOnErrorDeclaration, noEmitOnError for declaration

noEmitOnError do not ignore error when generating declaration files (d.ts)

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

I wonder if this should be a bug or a suggestion.

tsconfig.json has an option noEmitOnError, when set to false compiler generates javascript files and sourcemaps even if some types are missing.

tsconfig.json also has a declaration option for generating d.ts files, when set to true we get errors while generating output files even when noEmitOnError equals false.

📃 Motivating Example

Let's look at the simplest example. A website project that contains only 2 files file.ts and tsconfig.json

  • files.ts
function fn(): Coordinate {
    return { x: 0, y: 0 };
}   
  • tsconfig.json
{
    "compilerOptions": {
        "noImplicitAny": false,
        "noEmitOnError": false,
        "removeComments": false,
        "declaration": true, // <--- false: okay; true: get errors
        "sourceMap": true,
        "target": "es5"
    },
    "compileOnSave": true
}

The Coordinate is missing type. We can't generate output files.

  • (TS4060) Return type of exported function has or is using private name 'Coordinate'
    If we turn off (declaration = false), we can generate output files.

💻 Use Cases

We already have an option to emitOnError for JavaScript files, we should have emitOnError for declaration.

Why did I code and build typescript missing types?

  • When I develop, I use Visual Studio with a thousand packages from npm.
  • When I built my source code with Using-the-Compiler-API, I didn't install a thousand packages from npm. I'm looking for a way to ignore all errors when emitting output files for both js and d.ts. Right now, we are only able to ignore errors when emitting javascript files.

💡 What workarounds am I using in the meantime?

  • When Using-the-Compiler-API, I write a d.ts file manually and add them to the program before call program.emit(). With that trick I can get output in a quick way.
type Coordinate = any;

declare namespace Trade {
    type Order = any;
}

That works fine but it requires more work.

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

Reproduce the example using files.ts and tsconfig.json, then start with the compiler API's program.emit() behavior described in the issue. Compare declaration and JavaScript emission under noEmitOnError; done would provide a separately controllable way to emit declaration files despite errors, with appropriate coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.