Closed
Description
Bug Report
๐ Search Terms
tuples, inference, functions, parameters, parsing, arktype, mapped types
๐ Version & Regression Information
- This is the behavior in every version I tried (tested up to nightly)
โฏ Playground Link
Playground link with relevant code
๐ป Code
type MorphTuple = [string, "|>", any]
type validateMorph<def extends MorphTuple> = def[1] extends "|>"
? [validateDefinition<def[0]>, "|>", (In: def[0]) => unknown]
: def
type validateDefinition<def> = def extends MorphTuple
? validateMorph<def>
: {
[k in keyof def]: validateDefinition<def[k]>
}
declare function type<def>(def: validateDefinition<def>): def
// Function input (x) inferred as "ark"
const shallow = type(["ark", "|>", (x) => x.length])
const objectLiteral = type({ a: ["ark", "|>", (x) => x.length] })
// Function input inferred as any (should be "ark")
const nestedTuple = type([["ark", "|>", (x) => x.length]])
๐๏ธ Description
I encountered this bug a few months ago and originally logged an issue within ArkType, but suspected it was a TS bug given the inconsistency in the behavior particularly between the object literal and tuple cases.
The goal of this minimal repro is to narrow the function's input definition and use the type of the first element to infer the input parameter for the third element's function type.