Coder Social home page Coder Social logo

Comments (3)

kityan avatar kityan commented on June 11, 2024 1

Anyway, I've just fixed "the issue" in my code generation pipeline with dirty string replacement: export interface Params {} -> export type Params = Record<string,never>
Maybe we just should add some option to the converter? Something like exposeEmptySchemaObjectWithNoAdditionalPropertiesAllowedAs?

from json-schema-to-typescript.

bcherny avatar bcherny commented on June 11, 2024

We have a test case covering this. But for the life of me I don't remember where in the spec I saw that this is the correct behavior.

Reading it now, the JSON-Schema Spec is a bit ambiguous: a schema that omits properties is equivalent to TypeScript's any (in that, every value is valid), but it's unclear whether properties: {} is also equivalent to any, or if it should be strictly interpreted as "nothing matches".

Would love a second pair of eyes, if you can help sleuth through the various versions of the JSON-Schema Spec to dig up the correct behavior.

from json-schema-to-typescript.

kityan avatar kityan commented on June 11, 2024

I suppose that a schema that omits properties is equivalent to TypeScript's any only if additionalProperties in schema resolved to true. Of course this is a very rare case. Here is the case: I have ajv validator in my json-rpc server pipeline. And it fails to validate request with any properties in args against the schema in my first message. But ts interface produced from this schema allows any properties. It's a bit inconsistent...

UPD: Also this should be consistent with another prop: unevaluatedProperties

from json-schema-to-typescript.

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.