Giter VIP home page Giter VIP logo

Comments (8)

ThomasAribart avatar ThomasAribart commented on May 12, 2024 1

Thanks @svsool ! Gonna have a look at it 👀

from json-schema-to-ts.

ThomasAribart avatar ThomasAribart commented on May 12, 2024

@svsool Thanks for the heads up. JSON-schemas are extendable, so yes, FromSchema should accept custom properties.

Modifying this as we speak.

from json-schema-to-ts.

ThomasAribart avatar ThomasAribart commented on May 12, 2024

@svsool Should be solved in 2.5.5, can you confirm this ?

Solved by #85

from json-schema-to-ts.

svsool avatar svsool commented on May 12, 2024

it works, thank you!

from json-schema-to-ts.

svsool avatar svsool commented on May 12, 2024

hey @ThomasAribart, unfortunately seems to be broken with json-schema-to-ts 3.7.2, TypeScript 5, and JSONSchema7:

image

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

from json-schema-to-ts.

ThomasAribart avatar ThomasAribart commented on May 12, 2024

@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

from json-schema-to-ts.

svsool avatar svsool commented on May 12, 2024

thank you @ThomasAribart 🙏

from json-schema-to-ts.

smartinio avatar smartinio commented on May 12, 2024

@ThomasAribart Hey 👋 This is unfortunately broken again in 2.12.0 as well as 3.0.0. Using your example

from json-schema-to-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.