Ways to get named type from Static? Issues? #911
-
I have found one way to get a named type [1] out of export const MySchema = Type.Object({ /* ...fields... */ });
// export type MySchema = Static<typeof MySchema>; // standard method
export interface MySchema extends Static<typeof MySchema> {} // produces named type This seems like a pretty standard TypeScript technique and I don't expect any issues to arise from it. However,
[1] Without a named type, when I hover over |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The only other way of doing it that I can think of is to use code generation and stop using I found a couple of instances of it being used in the wild and I've used interface/extends Static in my own projects, so I shall continue to do so. |
Beta Was this translation helpful? Give feedback.
@waynebloss Hi,
Ah, that's a interesting approach. There isn't really a standard / non-standard way to produce named type in TypeBox, but the technique you suggest seems very reasonable to me, I actually quite like it.
In terms of issues, I wouldn't anticipate any, but just to be mindful that
extends Static<T>
is only workable for types that produce structural object types. In terms of other approaches, there's none that I know of (as all conditional mapped types are computed type aliases), but if there is a technique, i would be interested in including that in TypeBox, the following would be ideal.Maybe one day :)
Hope this helps
S