The default that never runs
A typed tuple silently loses trailing defaulted fields.
What’s going wrong
A tuple parser promises exactly three strings: a required name, a role defaulting to "guest", and a tier defaulting to "standard". Inputs are a JSON array of dense arrays with zero to three elements. A missing trailing slot uses its default; a present value must be a string, including empty strings. null, numbers, booleans, objects and arrays are invalid. Return one {"ok":[name,role,tier]} per valid tuple, or {"error":index} for its first invalid or missing required slot. The first slot has no default. Preserve tuple order. An empty batch returns [].
Read one JSON value from stdin and print the specified JSON result to stdout. No actual network or external package is used.
Expected behavior
Distinguish a parser accepting an absent input from a parser producing a complete output.
Reproduction
[["Ada"]]
[{"ok":["Ada","guest","standard"]}][["Ada","admin","gold"]]
[{"ok":["Ada","admin","gold"]}][["Ada",null]]
[{"error":1}]Before you begin
- Start with tuple positions, required inputs and defaults that exist only at runtime.
- TypeScript unions, arrays, objects and functions
- Trace runtime behavior even when the program type-checks
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.