Skip to content

Inferred type of read-only objects isn't read-only #866

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

You must be logged in to vote

@sdc395 Sorry, just to respond to your original comment...

Just wondering why the following does not infer a read-only type.

The Type.Readonly modifier is representative of the readonly syntax modifier, not representative of the Readonly TS utility type (and it's a bit unfortunate about the naming conflict there). As of current, the Type.Readonly modifier only applies the top level type, it doesn't deeply traverse into the type.

ReadonlyDeep

You can however implement the TS utility type in the following way (TypeBox may provide this type in future (just need a reasonable name for it))

TypeScript Link Here

import * as Type from '@sinclair/typebox'

// ------------------------------------…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by sdc395
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants