Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does't work on deno? #47

Closed
biluohc opened this issue Oct 24, 2021 · 3 comments
Closed

Does't work on deno? #47

biluohc opened this issue Oct 24, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@biluohc
Copy link

biluohc commented Oct 24, 2021

deno: 1.15.2

import Ajv from "https://esm.sh/ajv@8.6.3";

const schema = {
  type: "object",
  "properties": {
    "foo": { "type": "string" },
    "bar": { "type": "number", "maximum": 3 },
  },
  required: ["foo", "bar"],
} as const;
const schemaString = JSON.stringify(schema);
console.info(schemaString);

const validate = new Ajv().compile(schema);

const test = (obj: any) => {
  if (validate(obj)) console.log("Valid:", obj);
  else console.log("invalid!:", obj, validate.errors);
};

test({ "foo": "abc", "bar": 2 });
test({ "foo": "abc", "bar": 9 });
test({ "foo": "ab", "bar": "2" });

// https://github.com/ThomasAribart/json-schema-to-ts
import { FromSchema } from "https://deno.land/x/json_schema_to_ts@v1.6.5-beta.1/index.d.ts";
type FooBar = FromSchema<typeof schema>;
const forbar: FooBar = { "foo": "abc", "bar": "x" };
console.log(forbar);

The code running output as follow, but const forbar: FooBar = { "foo": "abc", "bar": "x" }; should not compile success?

{"type":"object","properties":{"foo":{"type":"string"},"bar":{"type":"number","maximum":3}},"required":["foo","bar"]}
Valid: { foo: "abc", bar: 2 }
invalid!: { foo: "abc", bar: 9 } [
  {
    instancePath: "/bar",
    schemaPath: "#/properties/bar/maximum",
    keyword: "maximum",
    params: { comparison: "<=", limit: 3 },
    message: "must be <= 3"
  }
]
invalid!: { foo: "ab", bar: "2" } [
  {
    instancePath: "/bar",
    schemaPath: "#/properties/bar/type",
    keyword: "type",
    params: { type: "number" },
    message: "must be number"
  }
]
{ foo: "abc", bar: "x" }
@firstdorsal
Copy link

similar problem here

@ThomasAribart
Copy link
Owner

Hi @biluohc @firstdorsal and thanks for reporting this issue.

I'm not familiar with deno but I'll look into it ASAP.

@ThomasAribart ThomasAribart added the bug Something isn't working label May 1, 2022
@ThomasAribart
Copy link
Owner

Hi @biluohc @firstdorsal ! Everything seems fine with v2.4.0:

-zsh 2022-05-11 14-40-00

Can you confirm so I can close this issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants