How to pass schema with typescript?
See original GitHub issueI’ve been hammering the docs, trying to find out why I’m getting this issue up front.
How can I pass in a json schema without getting an initial type error?

No overload matches this call.
Overload 1 of 2, '(props: Readonly<FormProps<unknown>>): Form<unknown>', gave the following error.
Type '{ title: string; description: string; type: string; required: string[]; properties: { firstName: { type: string; title: string; default: string; }; lastName: { type: string; title: string; }; telephone: { type: string; title: string; minLength: number; }; }; }' is not assignable to type 'JSONSchema7'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"string" | "number" | "boolean" | "object" | "integer" | "array" | "null" | JSONSchema7TypeName[] | undefined'.
Overload 2 of 2, '(props: FormProps<unknown>, context?: any): Form<unknown>', gave the following error.
Type '{ title: string; description: string; type: string; required: string[]; properties: { firstName: { type: string; title: string; default: string; }; lastName: { type: string; title: string; }; telephone: { type: string; title: string; minLength: number; }; }; }' is not assignable to type 'JSONSchema7'.ts(2769)
index.d.ts(44, 9): The expected type comes from property 'schema' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Form<unknown>> & Readonly<FormProps<unknown>> & Readonly<{ children?: ReactNode; }>'
index.d.ts(44, 9): The expected type comes from property 'schema' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Form<unknown>> & Readonly<FormProps<unknown>> & Readonly<{ children?: ReactNode; }>'
With as const
:
(JSX attribute) schema: JSONSchema7
No overload matches this call.
Overload 1 of 2, '(props: Readonly<FormProps<unknown>>): Form<unknown>', gave the following error.
Type '{ readonly title: "A registration form"; readonly description: "A simple form example."; readonly type: "object"; readonly required: readonly ["firstName", "lastName"]; readonly properties: { readonly firstName: { ...; }; readonly lastName: { ...; }; readonly telephone: { ...; }; }; }' is not assignable to type 'JSONSchema7'.
Types of property 'required' are incompatible.
The type 'readonly ["firstName", "lastName"]' is 'readonly' and cannot be assigned to the mutable type 'string[]'.
Overload 2 of 2, '(props: FormProps<unknown>, context?: any): Form<unknown>', gave the following error.
Type '{ readonly title: "A registration form"; readonly description: "A simple form example."; readonly type: "object"; readonly required: readonly ["firstName", "lastName"]; readonly properties: { readonly firstName: { ...; }; readonly lastName: { ...; }; readonly telephone: { ...; }; }; }' is not assignable to type 'JSONSchema7'.ts(2769)
index.d.ts(44, 9): The expected type comes from property 'schema' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Form<unknown>> & Readonly<FormProps<unknown>> & Readonly<{ children?: ReactNode; }>'
index.d.ts(44, 9): The expected type comes from property 'schema' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Form<unknown>> & Readonly<FormProps<unknown>> & Readonly<{ children?: ReactNode; }>'
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Using with TypeScript - Ajv JSON schema validator
With typescript, your compiled parsers and serializers can be type-safe, either taking their type from schema type or from type parameter passed to...
Read more >json-schema-to-typescript - npm
Start using json-schema-to-typescript in your project by running `npm i ... You can pass any of the options described above (including style ...
Read more >How to pass schema type: Object's key rules - Stack Overflow
I understood which you want to validate the testType object. Then there are two ways: You can add the blackbox: true, this will...
Read more >How to make Mongo schema from pure Typescript classes
Typescript files are helpful to create Mongo Schema. ... Move to scr folder and create database folder cd src mkdir database # Move...
Read more >Designing the perfect Typescript schema validation library
const schema = yup.object({ asdf: yup.string(), }); schema.validate({}); // passes. Yet the inferred type indicates that all properties are ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
To add to the previous comment, for complete type checking, you’d want to do this:
You can try this