ajv-validator / ajv

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
https://ajv.js.org
MIT License
13.84k stars 877 forks source link

JTDSchemaType derivation for enums is too strict #2358

Open swachter opened 10 months ago

swachter commented 10 months ago

What version of Ajv are you using? Does the issue happen if you use the latest version?

8.12.0

Ajv options object

none

Your code

type AB = 'a' | 'b'
const s1 = { enum: ['a', 'b'] } as const
const enum1: JTDSchemaType<AB> = s1
// error: The type 'readonly ["a", "b"]' is 'readonly' and cannot be assigned to the mutable type 'AB[]'.

What results did you expect?

Assignment should be possible.

Are you going to resolve the issue? I can prepare a PR

epoberezkin commented 9 months ago

This is not something that is easy (or maybe even possible) to improve given typescript type system limitations.

StefanWachter1507 commented 9 months ago

Did you see https://github.com/ajv-validator/ajv/pull/2359?