More jsonSchema woes with Typescript
See original GitHub issueThanks 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:
- Created 4 years ago
- Comments:8
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@imwillhang I just released a new version that no longer requires the explicit type. It was more trouble than it was worth.
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.That’s quite dramatic 😀 What else is broken?