Skip to content

TypeScript: passing schema via variable doesn't work #173

@bsnote

Description

@bsnote

TypeScript fails to compile the following snippet:

import createValidator = require('is-my-json-valid');

const schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    age: { type: 'number' },
  },
  required: [
    'name'
  ]
};

createValidator(schema);

showing the following error:

[ts]
Argument of type '{ type: string; properties: { name: { type: string; }; age: { type: string; }; }; required: string[]; }' is not assignable to parameter of type 'AnySchema'.
  Type '{ type: string; properties: { name: { type: string; }; age: { type: string; }; }; required: string[]; }' is not assignable to type 'AnyOneOfSchema'.
    Property 'oneOf' is missing in type '{ type: string; properties: { name: { type: string; }; age: { type: string; }; }; required: string[]; }'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions