Skip to content

Add option for generate interface with readonly properties #131

@ikokostya

Description

@ikokostya

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions