Print nested options by depth and polymorphic option code as overloads
Why
A nested match and a polymorphic function at a nested option failed tsc under -bs-emit-ts. The marker arm printed every depth as number, { readonly BS_PRIVATE_NESTED_SOME_NONE: number }, so no true declaration of valFromOption gave the payload back: at depth 0 it returns undefined, at depth d > 0 the marker of depth d - 1. And a function whose type parameter is an option's payload was bounded to the primitives, so getOr at 'a = option<int> (NestMatch.useNested) and Stdlib_Option.getOr at that instance (Memo.cached) had no signature.
modifiedRepresentation option under -bs-emit-ts
representation
modifiedJS -bs-emit-ts polymorphic option code
let getOr = (o: option<'a>, d: 'a) => switch o { | Some(v) => v | None => d }
js
modifiedJS -bs-emit-ts a function returning undefined alone
let useNestedFolded = () => getOr(Some(None), Some(3))js
The examples NestMatch (nested matches, getOr at a nested instance) and Memo (Stdlib_Option.getOr at 'a = option<int>) join the build test.
Review
- Why is each overload true? It is the function's signature at the instance
'a := option^k<a>, k = 0 or 1, withabounded to the primitives as before, printed by the same rule: the function's code is the code of every instance. The signature the body carries is the deepest instance's, which no caller sees; tsc checks the body there. - Why no conditional type for
Some<A>?Some<A>at an unboundedAis true only if no value but the runtime's markers owns the keyBS_PRIVATE_NESTED_SOME_NONE; a record type admits values owning further keys. The overloads hold at primitive payloads with no assumption. - What do the runtime declarations state?
Primitive_option.someandvalFromOption, andStdlib_Option.getOr, one signature per nesting of a primitive payload, up to an option of an option; each line audited against Primitive_option.res and Stdlib_Option.res.Stdlib_Option.mapkeeps its primitive signature. - Does this change genType's output? No: the marker hook answers "no marker" outside -bs-emit-ts, and the gentype tests' outputs are unchanged.