question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to pass schema with typescript?

See original GitHub issue

I’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?

Screen Shot 2020-08-20 at 10 00 58 PM
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:closed
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
matthias-ccricommented, Aug 24, 2020

To add to the previous comment, for complete type checking, you’d want to do this:

const schema: JSONSchema7 = { ... };
....
schema={schema}
12reactions
abdvlcommented, Aug 23, 2020

You can try this

import { JSONSchema7 } from "json-schema";
....
 schema={schema as JSONSchema7}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found