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.

TypeScript Issue with JTDSchema and Elements Properties

See original GitHub issue

When trying to specify a simple schema with an array of strings TypeScript produces a TypeScript compilation error. The same schema run in plain javascript works correctly.

Screen Shot 2021-08-25 at 1 26 24 PM

What version of Ajv are you using? Does the issue happen if you use the latest version?

Ajv 8.6.2

TypeScript 4.3.5

Ajv options object

import Ajv, { JTDSchemaType } from 'ajv/dist/jtd'

const ajv = new Ajv()

JSON Schema

interface Schema {
  x: Date
  y: [string]
}

const schema: JTDSchemaType<Schema> = {
  properties: {
    x: { type: 'timestamp' },
    y: {
      elements: { type: 'string' }
    }
  }
}

Your code

import Ajv, { JTDSchemaType } from 'ajv/dist/jtd'

const ajv = new Ajv()

interface Schema {
  x: Date
  y: [string]
}

const schema: JTDSchemaType<Schema> = {
  properties: {
    x: { type: 'timestamp' },
    y: {
      elements: { type: 'string' }
    }
  }
}

ajv.compile(schema)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewBarbacommented, Aug 25, 2021

Oh man. I’m sorry. Coming from Swift…

0reactions
epoberezkincommented, Aug 25, 2021

JTD catches type errors 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using with TypeScript - Ajv JSON schema validator
Utility type for JTD data type. You can use JTD schema to construct the type of data using utility type JTDDataType. JSON Type...
Read more >
Json Schema which has at least one of any properties (or ...
I am using ajv and Typescript and this is the code: interface MyData { foo: number; bar: string; } const schema: JSON ...
Read more >
Learn JSON Typedef in 5 Minutes
Learn JSON Typedef in 5 Minutes. This article is a tutorial that will teach you everything you need to know to understand any...
Read more >
type coercion typescript
Properties forms inside mapping cannot be nullable and cannot define the same ... Empty JTD schema defines the data instance that can be...
Read more >
JSON Type Definition RFC 8927 - IETF Datatracker
A "properties" form of JSON objects, corresponding to some sort of struct or record. ... As an example of a correct JTD schema...
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