-
Notifications
You must be signed in to change notification settings - Fork 413
Open
Description
The problem
I want to generate interface for object which must not be changed. I can manually wrap result using DeepReadonly
type:
type DeepReadonly = {
readonly [P in keyof T]: DeepReadonly<T[P]>;
};
but it doesn't work with arrays:
- Support
readonly
type operator to allow correct definition ofObject.freeze
microsoft/TypeScript#10725 - Suggestion: DeepReadonly<T> type microsoft/TypeScript#13923
Suggestion
Add some option to json-schema-to-typescript
for generating readonly properties. For example from README.md
:
export interface ExampleSchema {
readonly firstName: string;
readonly lastName: string;
readonly age?: number;
readonly hairColor?: "black" | "brown" | "blue";
}
For arrays ReadonlyArray
type can be used:
export interface ExampleSchema {
readonly arr: ReadonlyArray<string>
}
Questions
Unfortunately there is no way to create read only tuple (as I known) if json-schema-to-typescript
produces it.
peterhudec, narkowicz, vsund, knopki, christhekeele and 7 more