Skip to content

Is there support for readonly arrays? #860

Answered by sinclairzx81
thes01 asked this question in Q&A
Discussion options

You must be logged in to vote

@thes01 Hi,

Is there any support for such type to be expressed in Typebox schemas?

Unfortunately, there's not currently a way to infer isolated readonly tuples (i.e. those not embedded in outer types) but Unsafe is a reasonable workaround. The reason has to do with the way TB inference works; where an outer type (TObject, TFunction and TConstructor) will ascribe the readonly modifier to the interior type. As isolated types don't have an outer type, there is nothing to ascribe the modifier.

This said, following is a ReadonlyTuple type that will perform the isolated readonly inference via Unsafe (if you need a a type to handle this)

TypeScript Link Here

import { Type, Static, TSchema } from 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@thes01
Comment options

Answer selected by thes01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants