process.stdin.on(data/end): SC0001 for Buffer listener, setEncoding silently ignored

Aperta
#3,530 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
53/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend

Direzione di ricerca

Start with the fallback stdin declarations in packages/compiler/ambient/scriptc-node-fallback.d.ts, around lines 401–470, and trace how stdin event listeners and setEncoding are lowered. Reproduce both examples from the issue, then check the related issues #3352, #3427, and #3445 for existing design context. Done means Buffer listeners work and setEncoding either produces string chunks or fails with a diagnostic.

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

Descrizione

scriptc 0.4.11, main at 918d80b26a, macOS arm64.

Two problems with process.stdin as an event emitter.

  1. Typed Buffer listener is refused:
const chunks: Buffer[] = [];
process.stdin.on("data", (c: Buffer) => chunks.push(c));
process.stdin.on("end", () => console.log(Buffer.concat(chunks).length));

Actual: SC0001: No overload matches this call ... Argument of type '"data"' is not assignable to parameter of type '"keypress"'. The fallback declarations in packages/compiler/ambient/scriptc-node-fallback.d.ts (stdin, around lines 401-470) lack the data/end overloads.

  1. Silent miscompile with setEncoding:
let buf = "";
process.stdin.setEncoding("utf8");
process.stdin.on("data", (c) => { buf += c; console.error(typeof c); });
process.stdin.on("end", () => console.log(JSON.stringify(buf)));

echo '{"a":1}' | ./out prints object and "123,34,97,34,58,49,125,10". Expected string and "{\\"a\\":1}\\n". The build succeeds with no diagnostic, so setEncoding is ignored and chunks stay byte arrays.

for await (const c of process.stdin) with Buffer.concat works.

Expected: either lower both forms or refuse setEncoding loudly. Related: #3352, #3427, #3445.

Lingua principale
TypeScript
Stelle
6.5k
Fork
212
Merge medio
13h 46m
PR unite (30g)
787

Preparare l'ambiente

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.

Altre issue di vercel-labs/scriptc

Tutte le issue di vercel-labs/scriptc

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.