microsoft / microsoft/TypeScript

[isolatedDeclarations] Optional parameter properties are unnecessarily disallowed in isolatedDeclarations mode

Aperta
#61,501 1 commento 2 reazioni 1 assegnatario Vedi su GitHub

@weswigham ci sta già lavorando.

Dal 28/3/2025.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

### 🔎 Search Terms

optional parameter properties, isolated declarations, TS9025: Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations

### 🕗 Version & Regression Information

- This was present since the introduction of isolatedDeclarations in TS5.5

### ⏯ Playground Link

https://www.typescriptlang.org/play/?downlevelIteration=true&importHelpers=true&target=99&module=1&isolatedDeclarations=true&ts=5.8.2&ssl=6&ssc=2&pln=1&pc=1#code/C4TwDgpgBAsghiARhAqgOwCYQGYEs0QZQC8UaArgLbIBOUAPlOZjvoQNwBQokUAchABuEGuix4CRUhWoiunCAA8wAexrAoAYwA2cAM56oAMRUqoAb05RrWlWj3Aa5TcDUAKGhDgY72kFEUAfgAuWARkMVZJABooT29ffxAQ-iERSIlCAEoLAF9OXKA

### 💻 Code

```ts
type MaybeUndefined = number | undefined;
type NeverUndefined = number;

export class Foo {
constructor(readonly x?: MaybeUndefined, readonly y?: NeverUndefined) {}
}
```

### 🙁 Actual behavior

Gives an error:
> Declaration emit for this parameter requires implicitly adding undefined to its type. This is not supported with --isolatedDeclarations.

### 🙂 Expected behavior

It seems like this could be safely supported by just always emitting the class fields with a type of `|undefined` whether that was redundant or not, something like:
```
export declare class Foo {
readonly x?: MaybeUndefined | undefined;
readonly y?: NeverUndefined | undefined;
constructor(x?: MaybeUndefined, y?: NeverUndefined);
}
```

### Additional information about the issue

The workaround of explicitly adding `|undefined` to the parameter property types is not too onerous, but still seems like an unnecessary restriction for `isolatedDeclarations` mode.

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.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.