Repository: TypeScript
Issue: Need an option for ignore error when emit declaration
Labels: Suggestion,Awaiting More Feedback

# Suggestion

## 🔍 noEmitOnErrorDeclaration, noEmitOnError for declaration

<!--
  💡 Did you know? TypeScript has over 2,000 open suggestions!
  🔎 Please search thoroughly before logging new feature requests as most common ideas already have a proposal in progress.
  The "Common Feature Requests" section of the FAQ lists many popular requests: https://github.com/Microsoft/TypeScript/wiki/FAQ#common-feature-requests

  Replace the text below:
-->
[noEmitOnError](https://www.typescriptlang.org/tsconfig#noEmitOnError) do not ignore error when generating declaration files (d.ts)

## ✅ Viability Checklist

<!--
   Suggestions that don't meet all these criteria are very, very unlikely to be accepted.
   We always recommend reviewing the TypeScript design goals before investing time writing
   a proposal for ideas outside the scope of the project.
-->
My suggestion meets these guidelines:

* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
* [x] This wouldn't change the runtime behavior of existing JavaScript code
* [x] This could be implemented without emitting different JS based on the types of the expressions
* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-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
```ts
function fn(): Coordinate {
    return { x: 0, y: 0 };
}   
```
- tsconfig.json
```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](https://github.com/microsoft/TypeScript/wiki/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](https://github.com/microsoft/TypeScript/wiki/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.
```d.ts
type Coordinate = any;

declare namespace Trade {
    type Order = any;
}
```
That works fine but it requires more work.

<!--
  What do you want to use this for?
  What shortcomings exist with current approaches?
  What workarounds are you using in the meantime?
-->