Closed svsool closed 1 year ago
@svsool Thanks for the heads up. JSON-schemas are extendable, so yes, FromSchema
should accept custom properties.
Modifying this as we speak.
@svsool Should be solved in 2.5.5, can you confirm this ?
Solved by https://github.com/ThomasAribart/json-schema-to-ts/pull/85
it works, thank you!
hey @ThomasAribart, unfortunately seems to be broken with json-schema-to-ts 3.7.2, TypeScript 5, and JSONSchema7:
this is package.json:
{
"name": "schema-repro",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"type": "module",
"scripts": {
"ts": "tsc --project ./tsconfig.json --noEmit"
},
"devDependencies": {
"@tsconfig/esm": "^1.0.2",
"@tsconfig/node18": "^1.0.1",
"@tsconfig/strictest": "^2.0.0",
"json-schema-to-ts": "2.5.2",
"typescript": "^5.0.3"
}
}
and types.ts:
import type { FromSchema } from 'json-schema-to-ts';
export const countryCode = {
type: 'string',
allOf: [
{
transform: ['trim'],
},
{
minLength: 2,
maxLength: 3,
},
],
} as const;
export type CountryCode = FromSchema<typeof countryCode>;
tsconfig.json:
{
"extends": ["@tsconfig/strictest/tsconfig.json", "@tsconfig/node18/tsconfig.json", "@tsconfig/esm/tsconfig.json"],
"compilerOptions": {
"typeRoots": ["node_modules/@types"],
"outDir": "build",
"baseUrl": "src",
"sourceMap": true,
"downlevelIteration": true,
"resolveJsonModule": true,
"exactOptionalPropertyTypes": false,
"noImplicitReturns": false,
"noPropertyAccessFromIndexSignature": false,
"noUncheckedIndexedAccess": false,
"noUnusedParameters": false,
"checkJs": false,
},
"exclude": ["node_modules"]
}
run yarn ts
to reproduce
Thanks @svsool ! Gonna have a look at it 👀
@svsool Should work in 2.8.0 with the new ExtendedJSONSchema
and FromExtendedSchema
types:
type Extension = {
transform: string[];
};
export const countryCode = {
type: "string",
allOf: [
{
transform: ["trim"],
},
{
minLength: 2,
maxLength: 3,
},
],
} as const;
export type CountryCode = FromExtendedSchema<Extension, typeof countryCode>;
// => string
thank you @ThomasAribart 🙏
@ThomasAribart Hey 👋 This is unfortunately broken again in 2.12.0 as well as 3.0.0. Using your example
Hi, thanks for this library.
I noticed that
FromSchema
utility does not work with ajv-keywords such astransform: ['trim']
for example. Seems like a bug to me.Code to reproduce: