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.

More jsonSchema woes with Typescript

See original GitHub issue

Thanks so much for your help. We were happily deploying objection 1.6.11 in production with Typescript until we upgraded to 2.0.10, and everything went down from there.

My issue is that: After updating from objection 1.6.11 to 2.0.10, I am seeing the following Typescript errors coming from our Model declarations. We had received no issues prior to the upgrade.

src/db/models/ExampleTable.ts(4,7): error TS2417: Class static side 'typeof ExampleTable' incorrectly extends base class static side 'typeof Model'.
Types of property 'jsonSchema' are incompatible.
    Type '{ properties: { id: { type: string; }; property1: { type: string; }; property2: { type: string; }; property3: { type: string; }; }; type: string; }' is not assignable to type 'JSONSchema'.
        Types of property 'type' are incompatible.
            Type 'string' is not assignable to type '"string" | "number" | "boolean" | "object" | "integer" | "array" | "null" | JSONSchemaTypeName[]'.
  • We are on the latest version of Knex
  • I am aware of issue #1615 and have a feeling that it is related. However, I could not find a way to import the JSONSchema type to cast jsonSchema to.

Here is an example of our Model declaration file:

import objection from "objection";
import path from "path";

class ExampleTable extends objection.Model {
	public id?: number;
	public property1: number;
	public property2?: object;
	public property3?: object;

	static get tableName() {
		return "exampletable";
	}

	static get idColumn() {
		return "id";
	}

	static get jsonSchema() {
		return {
			properties: {
				id: { type: "integer" },
				property1: { type: "integer" },
				property2: { type: "string" },
				property3: { type: "string" },
			},
			type: "object"
		};
	}
}
export default ExampleTable;

Thank you again!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
koskimascommented, Jan 8, 2020

@imwillhang I just released a new version that no longer requires the explicit type. It was more trouble than it was worth.

1reaction
koskimascommented, Dec 31, 2019
static get jsonSchema(): JSONSchema {

The new json schema typings are more strict and you need to add the explicit type telling typescript that some strings are in fact enums. The JSONSchema type can be imported from objection.

until we upgraded to 2.0.10, and everything went down from there.

That’s quite dramatic 😀 What else is broken?

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Node TypeScript JSON Schema validation using TypeBox
In today's article I will explain how we can define a JSON Schema and perform its data validation using the TypeBox library in...
Read more >
json-schema-to-typescript - npm package - Snyk
The npm package json-schema-to-typescript was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was deemed as ......
Read more >
Statically Typed Data Validation with JSON Schema and ...
How to use JSON schema to validate data and generate the corresponding TypeScript types for flexible, declarative data validation.
Read more >
typescript-json-schema examples - CodeSandbox
Latest version0.55.0. LicenseBSD-3-Clause ; Size3616.055Kb. Packages Using it ; Issues Count515. Stars2546.
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