ajv-validator / ajv-validator/ajv

JSONSchemaType incorrectly parsing generic type as never

未关闭
#2,219 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
limitation
主要语言
TypeScript
星标
14.8k
派生
1k
PR 合并指标
30 天内没有已合并 PR

描述

**What version of Ajv are you using? Does the issue happen if you use the latest version?**
8.12.0, yes

**Ajv options object**

```{}```

```javascript
import {JSONSchemaType} from "ajv"

const toSchema = >(properties: { [key: string]: any}): JSONSchemaType => {
return {
type: 'object',
properties,
required: []
}
}
```

**JSON Schema**
NA

**Sample data**
NA

**Your code**
[TS Playground](https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbwFIGUDyA5FBjAFgUxAEMAVATzHwF84AzKCEOAIiICsA3ZgKG+wgB2AZ3gwIOAsTgBeOAB4ScfAA8Y+AQBMhcAEr5+UDXJFRgAgOYAaOEQFkAfPYAUYBpVjB8QgFyI4AbQBrfDJfEzNzAF1fWzIqAEpfVEwJQlIKfAV7GWyEbjg4KHwYAFcoAUR8grgYDN8AcggAIzZ9GHrLKoLXCHcYTyFO6sL8AEcS4CKNX39IqqpuKiA)

```javascript
import {JSONSchemaType} from "ajv"

const toSchema = >(properties: { [key: string]: any}): JSONSchemaType => {
return {
type: 'object',
properties,
required: []
}
}
```

**Validation result, data AFTER validation, error messages**

```
Type '{ type: "object"; properties: { [key: string]: any; }; required: never[]; }' is not assignable to type 'UncheckedJSONSchemaType'.
Object literal may only specify known properties, and 'type' does not exist in type 'never'.
```

**What results did you expect?**
I expected the type to compile without issue. It looks like the UncheckedJSONSchemaType is not correctly parsing the various if/else statements, so it ends up falling back to `never`. The error messaging here is pretty bad, but even when explicitly extending the generic from `Record` ajv fails, which is surprising.

**Are you going to resolve the issue?**
Maybe

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。