ajv-formats icon indicating copy to clipboard operation
ajv-formats copied to clipboard

How to use it with typescript for type safety?

Open shahinghasemi opened this issue 1 year ago • 0 comments

How can I use this package with type safety? Is there any way to extend JsonScehamType<T> to includes the types for ajv-format? I couldn't find a way to do that.

import { JSONSchemaType } from 'ajv';

type Example = {
  age: number;
  name: string;
};
const sample: JSONSchemaType<Example> = {
  type: 'object',
  properties: {
    age: { type: ['integer'] },
    name: {type: ['string'], format: ['']}
  },
};

In the above example I want to apply some formats to name but it's type is string.

thanks.

shahinghasemi avatar Feb 19 '24 12:02 shahinghasemi