Skip to content

Need an option for ignore error when emit declarationΒ #54305

Open
@XHighIntell

Description

@XHighIntell

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions