Skip to content

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

Open

Description

@espetro

scriptc 0.4.11, main at 918d80b, 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions