lib.dom.d.ts: Transformer is missing the `cancel` member that WHATWG Streams defines
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
- #65023 par @timurzvural — fermée sans fusion
Évaluation
- Difficulté
- 3/5
- Temps estimé
- Une demi-journée
- Accessibilité débutants
- 52/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- typescript
- Domaine
- tooling
Piste de recherche
Start by reading the generated DOM and WebWorker declarations for Transformer, especially dom.generated.d.ts and lib.webworker.d.ts, and check how their callback types are defined. The issue reports a closed, unmerged pull request, so first review that work and the current declaration generation flow. Done means both interfaces expose the standard cancel member with an appropriate callback type and the reported TypeScript reproduction compiles.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
lib.dom.d.ts declares interface Transformer without the cancel member, but
the WHATWG Streams standard includes it and Node implements it. Any
new TransformStream({ ..., cancel() {} }) therefore fails to compile with
TS2353, even though the handler is valid and gets called when the readable side
is cancelled.
Reproduced on TypeScript 6.0.3 and 7.0.2.
Standards reference
WHATWG Streams, Transformer dictionary
(https://streams.spec.whatwg.org/#dictdef-transformer) defines six members:
start, transform, flush, cancel, readableType, writableType
lib.dom.d.ts declares five of the six. cancel is missing:
interface Transformer<I = any, O = any> {
flush?: TransformerFlushCallback<O>;
readableType?: undefined;
start?: TransformerStartCallback<O>;
transform?: TransformerTransformCallback<I, O>;
writableType?: undefined;
}
Minimal reproduction
const ts = new TransformStream<Uint8Array, Uint8Array>({
transform(chunk, controller) { controller.enqueue(chunk); },
cancel() { /* client disconnected */ },
});
export { ts };
$ tsc --noEmit --target es2022 --lib dom,es2022 probe.ts
probe.ts(3,3): error TS2353: Object literal may only specify known properties,
and 'cancel' does not exist in type
'Transformer<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>'.
Identical output on 6.0.3 and 7.0.2.
The runtime does call it
Node 24.18.0, stream/web:
const ts = new TransformStream({
transform(c, ctrl) { ctrl.enqueue(c); },
cancel(reason) { console.log("transformer.cancel INVOKED", reason); },
});
await ts.readable.cancel("client-disconnect");
// -> transformer.cancel INVOKED client-disconnect
So cancel is not a dead optional member. It is the only hook that fires when
the readable side is cancelled, which for an SSE proxy is exactly the
client-disconnect case. Handlers here typically clear heartbeat and progress
intervals; removing them to satisfy the checker leaks a timer per abandoned
stream.
Why a declaration-merge workaround does not work
Filing this after trying the obvious local patch. Inside a module:
declare global {
interface Transformer<I = unknown, O = unknown> {
cancel?: (reason?: unknown) => void | PromiseLike<void>;
}
}
This does not merge. Interface declarations must agree on their type
parameters, and lib.dom.d.ts uses <I = any, O = any> while the natural
patch uses unknown. With skipLibCheck: true the resulting TS2428 is
suppressed, so the merge silently fails and cancel stays absent. Matching
any makes it merge, but then the default type arguments on every
TransformStream in the codebase degrade to any, which trades one problem
for another.
That dead end is the reason this is filed as a lib gap rather than handled
locally.
Suggested fix
Add the member to Transformer in dom.generated.d.ts, with a callback type
next to the other three:
interface Transformer<I = any, O = any> {
flush?: TransformerFlushCallback<O>;
readableType?: undefined;
start?: TransformerStartCallback<O>;
transform?: TransformerTransformCallback<I, O>;
cancel?: TransformerCancelCallback;
writableType?: undefined;
}
type TransformerCancelCallback = (reason?: any) => void | PromiseLike<void>;
lib.webworker.d.ts has the same interface and needs the same change.
Notes
- Checked 6.0.3 and 7.0.2; both reproduce.
- Searched the issue tracker for
Transformer cancelandlib.dom TransformStream
before filing; the results were unrelated, so this does not look like a
duplicate. - TypeScript version 7 ships lib files inside the platform binary, so the
reproduction uses the CLI rather than readinglib.dom.d.tsfrom disk.
- Langage dominant
- Go
- Étoiles
- 112k
- Forks
- 15.4k
- Merge moyen
- 2 j 21 h
- PR mergées (30 j)
- 126
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de microsoft/TypeScript
-
Won't Fix
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
microsoft/TypeScript#65107 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file locationPeut-être pris @timurzvural l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
microsoft/TypeScript#65087 ·
Les mainteneurs répondent en général sous 1 jour
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'Peut-être à nouveau libre Une pull request pour cette issue a été fermée sans être fusionnée. OuverteBug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
microsoft/TypeScript#64758 ·
Les mainteneurs répondent en général sous 1 jour
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`Peut-être pris @rajnish-verma-22172 l’a pris il y a 13 jours. OuverteBug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
microsoft/TypeScript#64742 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindingsPeut-être pris @dmety l’a pris il y a 26 jours. OuverteBug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
microsoft/TypeScript#64661 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de microsoft/TypeScript
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
-
cmd/ebitenmobile: multi-language bindings run the complete generator twicePeut-être pris @kumagi l’a pris aujourd’hui. Ouverteos:macos performance
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
hajimehoshi/ebiten#4011 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
agent-butler-finding chore
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
jordansmall/spindrift#6318 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Eyevinn/moqlivemock#166 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
JakeChampion/lang#14091 ·
Les mainteneurs répondent en général sous 1 jour