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

Readonly arrays not handled properly #1447

Closed
LinusU opened this issue Feb 16, 2021 · 1 comment
Closed

Readonly arrays not handled properly #1447

LinusU opened this issue Feb 16, 2021 · 1 comment

Comments

@LinusU
Copy link
Contributor

LinusU commented Feb 16, 2021

What version of Ajv are you using? Does the issue happen if you use the latest version? 7.1.0/master, yes

Ajv options object

{}

JSON Schema

{
  "additionalProperties": false,
  "properties": {
    "items": { "type": "array" },
  },
  "required": ["items"],
  "type": "object"
}

Sample data

n/a

Your code

interface TransactionInput {
  items: readonly { count: number, productId: string }[]
}

const transactionInputValidator = ajv.compile<TransactionInput>({
  additionalProperties: false,
  properties: {
    items: { type: 'array' }, // <--- Error: TS wants this to be "object"
  },
  required: ['items'],
  type: 'object'
})

Validation result, data AFTER validation, error messages

n/a

What results did you expect?

TypeScript to allow it to be an array

Are you going to resolve the issue?

Yes

@epoberezkin
Copy link
Member

merged - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants