Lean2Js.Dts
What the .d.ts says a value is, against the entry check the generated code runs #
What the .d.ts says a value of a declared type is, and how that compares with the entry check the
generated code runs.
TsSat is the reading of the text Js.tsType and Js.declareType write: a discriminated union over
the type's constructors, readonly T[] for an array, ReadonlyMap<string, V> for a dictionary, and
number for both Int53 and UInt32. TypeScript erases to nothing at runtime, so this is a reading of
a declaration and not a check that runs — that the reading is faithful to what TypeScript means by that
text is where the .d.ts is still taken on trust.
Fields are read the way a property access reads them: Js.lookupField, the first entry carrying that
name. Nothing here reads the order the keys arrive in, and nothing reads a key the type does not declare.
The two sets are the same, up to one point. checkTy_tsSat says the entry check is no more permissive
than the .d.ts; tsSat_checkTy says it is no less, given inRange — the numbers the value carries lie
in the Int53 and UInt32 ranges the check reads, which is what number cannot express. That is the
whole of what the converse assumes about a value.
Lean2Js.Dts.TsSat
source- dict : (∀ (e : String × Js.JsValue), e ∈ es → TsSat p t e.snd) → TsSat p t.dict (Js.JsValue.dict es)
- dictObjMap : (∀ (e : String × Js.JsValue), e ∈ es → TsSat p t e.snd) → TsSat p t.dictObj (Js.JsValue.dict es)
- dictObjLit : (∀ (e : String × Js.JsValue), e ∈ fs → TsSat p t e.snd) → TsSat p t.dictObj (Js.JsValue.obj fs)
- none : Js.lookupField jfs "tag" = Option.some (Js.JsValue.str "none") → TsSat p t.option (Js.JsValue.obj jfs)
- some : Js.lookupField jfs "tag" = Option.some (Js.JsValue.str "some") → Js.lookupField jfs "value" = Option.some x → TsSat p t x → TsSat p t.option (Js.JsValue.obj jfs)
- ok : Js.lookupField jfs "tag" = Option.some (Js.JsValue.str "ok") → Js.lookupField jfs "value" = Option.some x → TsSat p a x → TsSat p (a.result e) (Js.JsValue.obj jfs)
- error : Js.lookupField jfs "tag" = Option.some (Js.JsValue.str "error") → Js.lookupField jfs "error" = Option.some x → TsSat p e x → TsSat p (a.result e) (Js.JsValue.obj jfs)
- named : p.findType? n = Option.some t → c ∈ t.ctorsAt args → Js.lookupField jfs t.discriminator = Option.some (Js.JsValue.str c.name) → TsSatFields p c.fields jfs → TsSat p (Core.Ty.named n args) (Js.JsValue.obj jfs)
Instances For
Used by
Lean2Js.Dts.TsSatFields
source- cons : Js.lookupField jfs f.name = some x → TsSat p f.ty x → TsSatFields p fs jfs → TsSatFields p (f :: fs) jfs
Instances For
Used by
Lean2Js.Dts.TsSatFields.weaken
sourceUsed by
Lean2Js.Dts.lookup_key
sourceUsed by
Lean2Js.Dts.TsSatOut
sourceThe reading of the text Js.tsTypeOut writes: what the .d.ts says about a value on its way back
out. TsSat with the dictObjMap arm gone, because a dictionary that crosses as a plain object comes
back as one, and delegating to TsSat at a declared type, where one printed interface answers for both
directions.
- dict : (∀ (e : String × Js.JsValue), e ∈ es → TsSatOut p t e.snd) → TsSatOut p t.dict (Js.JsValue.dict es)
- dictObjLit : (∀ (e : String × Js.JsValue), e ∈ fs → TsSatOut p t e.snd) → TsSatOut p t.dictObj (Js.JsValue.obj fs)
- none : Js.lookupField jfs "tag" = Option.some (Js.JsValue.str "none") → TsSatOut p t.option (Js.JsValue.obj jfs)
- some : Js.lookupField jfs "tag" = Option.some (Js.JsValue.str "some") → Js.lookupField jfs "value" = Option.some x → TsSatOut p t x → TsSatOut p t.option (Js.JsValue.obj jfs)
- ok : Js.lookupField jfs "tag" = Option.some (Js.JsValue.str "ok") → Js.lookupField jfs "value" = Option.some x → TsSatOut p a x → TsSatOut p (a.result e) (Js.JsValue.obj jfs)
- error : Js.lookupField jfs "tag" = Option.some (Js.JsValue.str "error") → Js.lookupField jfs "error" = Option.some x → TsSatOut p e x → TsSatOut p (a.result e) (Js.JsValue.obj jfs)
Instances For
Used by
Lean2Js.Dts.TsSatOut.toTsSat
sourceWhat the returning side admits, the argument side admits as well, so a value a consumer got back from one call is one the next call's parameter type takes.
Used by
Lean2Js.Dts.hasTy_tsSat
sourceWhat a declaration hands back fits the published .d.ts. The reading is encodeAt — the value read
out through the type the declaration was declared to return — because that is what the entry returns:
at a dictObj it walks a Map into a plain object, and the .d.ts admits both.
Used by
Lean2Js.Dts.tsSatList_encodeListAt
sourceUsed by
Lean2Js.Dts.tsSatEntries_encodeEntriesAt
sourceUsed by
Lean2Js.Dts.tsSatFields_encodeFieldsAt
sourceUsed by
Lean2Js.Dts.hasTy_tsSatOut
sourceWhat a declaration hands back fits the narrower type the .d.ts prints for a return. The only place
it says more than hasTy_tsSat is a dictObj, where the entry has already walked the Map out into a
plain object and so the union the argument side prints is not needed.
Used by
Lean2Js.Dts.tsSatOutList_encodeListAt
sourceUsed by
Lean2Js.Dts.tsSatOutEntries_encodeEntriesAt
sourceUsed by
Lean2Js.Dts.checkTy_tsSat
sourceWhat the entry check lets through, the .d.ts admits. tsSat_checkTy is the other direction, which
needs the number range the .d.ts cannot carry.
Used by
Lean2Js.Dts.checkFields_tsSat
sourceUsed by
Lean2Js.Dts.checkList_tsSat
sourceUsed by
Lean2Js.Dts.checkEntries_tsSat
sourceUsed by
The one thing a TypeScript type cannot say #
Js.checkTy reads an Int53 or UInt32 range off a number, and number carries no range. inRange is
that reading on its own: Js.checkTy with every shape test passing, so the only way it comes out false is
a number outside the range the descriptor names at that position. Nothing runs it — it is what
tsSat_checkTy assumes, and holding it apart from TsSat is what keeps that assumption down to one.
Lean2Js.Dts.inRange
sourceEquations
- One or more equations did not get rendered due to their size.
- Lean2Js.Dts.inRange env (Lean2Js.Js.JsValue.num i) Lean2Js.Js.TyDesc.int53 = (decide (Lean2Js.Js.Runtime.safeMin ≤ i) && decide (i ≤ Lean2Js.Js.Runtime.safeMax))
- Lean2Js.Dts.inRange env (Lean2Js.Js.JsValue.num i) Lean2Js.Js.TyDesc.uint32 = (decide (0 ≤ i) && decide (i < Lean2Js.Js.Runtime.wrap32))
- Lean2Js.Dts.inRange env (Lean2Js.Js.JsValue.arr xs) t.array = Lean2Js.Dts.inRangeList env xs t
- Lean2Js.Dts.inRange env (Lean2Js.Js.JsValue.dict entries) t.dict = Lean2Js.Dts.inRangeEntries env entries t
- Lean2Js.Dts.inRange env (Lean2Js.Js.JsValue.dict entries) t.dictObj = Lean2Js.Dts.inRangeEntries env entries t
- Lean2Js.Dts.inRange env (Lean2Js.Js.JsValue.obj fields) t.dictObj = Lean2Js.Dts.inRangeEntries env fields t
- Lean2Js.Dts.inRange env x✝ (Lean2Js.Js.TyDesc.mu key alts) = Lean2Js.Dts.inRange ((key, alts) :: env) x✝ (Lean2Js.Js.TyDesc.ctors key alts)
- Lean2Js.Dts.inRange env x✝ (Lean2Js.Js.TyDesc.ref up) = match env[up]? with | some b => Lean2Js.Dts.inRange (List.drop up env) x✝ (Lean2Js.Js.TyDesc.ctors b.fst b.snd) | none => true
- Lean2Js.Dts.inRange env x✝¹ x✝ = true
Instances For
Used by
Lean2Js.Dts.inRangeFields
sourceEquations
- One or more equations did not get rendered due to their size.
- Lean2Js.Dts.inRangeFields env fields [] = true
Instances For
Used by
Lean2Js.Dts.inRangeList
sourceEquations
- Lean2Js.Dts.inRangeList env [] x✝ = true
- Lean2Js.Dts.inRangeList env (x_2 :: rest) x✝ = (Lean2Js.Dts.inRange env x_2 x✝ && Lean2Js.Dts.inRangeList env rest x✝)
Instances For
Used by
Lean2Js.Dts.inRangeEntries
sourceEquations
- Lean2Js.Dts.inRangeEntries env [] x✝ = true
- Lean2Js.Dts.inRangeEntries env ((fst, v) :: rest) x✝ = (Lean2Js.Dts.inRange env v x✝ && Lean2Js.Dts.inRangeEntries env rest x✝)
Instances For
Used by
Lean2Js.Dts.inRange_int53
sourceUsed by
Lean2Js.Dts.inRange_uint32
sourceUsed by
Lean2Js.Dts.inRange_array
sourceUsed by
Lean2Js.Dts.inRange_dict
sourceUsed by
Lean2Js.Dts.inRange_dictObj_dict
sourceUsed by
Lean2Js.Dts.inRange_dictObj_obj
sourceUsed by
Lean2Js.Dts.inRange_some
sourceUsed by
Lean2Js.Dts.inRange_ok
sourceUsed by
Lean2Js.Dts.inRange_error
sourceUsed by
Lean2Js.Dts.inRange_ctors
sourceUsed by
Lean2Js.Dts.inRangeList_cons
sourceUsed by
Lean2Js.Dts.inRangeEntries_cons
sourceUsed by
Lean2Js.Dts.inRangeFields_found
sourceUsed by
Everything the .d.ts admits, the entry check accepts #
The direction a caller feels. TsSat reads fields by name, so the order they arrive in is not read;
Js.checkFields reads only the names the descriptor carries, so a key the type does not declare is not
read either. What is left is inRange.
Lean2Js.Dts.tsSat_option_shape
sourceUsed by
Lean2Js.Dts.tsSat_result_shape
sourceUsed by
Lean2Js.Dts.tsSat_named_shape
sourceUsed by
Lean2Js.Dts.tsSat_array_shape
sourceUsed by
Lean2Js.Dts.tsSat_dict_shape
sourceUsed by
Lean2Js.Dts.find?_of_mem_nodup
sourceA constructor of a validated type is the one its own name finds.
Used by
Lean2Js.Dts.tsSat_checkTy
sourceEverything the published .d.ts admits, the entry check accepts. The only thing assumed about the
value is inRange: the order its keys arrive in is not read, and neither are keys the type does not
declare.