|
|
|
|
|
by eyelidlessness
1194 days ago
|
|
Types are absolutely available at runtime, you just have to start from the runtime. Type guards are the solution everyone wants +- a tiny bit of ceremony, and adding type system information to the runtime would just hurt performance for no good reason. This: type Foo = {
bar: string
// …
}
Can just as easily be addressed as: const parseFoo = parse.object({
bar: parse.string,
// …
})
type Foo = Foo<typeof parseFoo>
(Where parse methods here are type guards for their respective parsed return types, and can similarly be used to serialize runtime values as needed.)For that little bit of extra ceremony, you get to isolate runtime stuff to the boundaries you need to care about, and let the type checker deal with everything else (typically most everything internal). |
|