microsoft / microsoft/TypeScript

Need an option for ignore error when emit declaration

Aperta
#54,305 8 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci l’esempio usando files.ts e tsconfig.json, quindi inizia dal comportamento di program.emit() della compiler API descritto nell’issue. Confronta l’emissione delle dichiarazioni e di JavaScript con noEmitOnError; done fornirebbe un modo controllabile separatamente per emettere i file di dichiarazione nonostante gli errori, con una copertura adeguata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.