loopbackio / loopbackio/loopback-next
Invalid TS models when properties are nullable
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- TypeScript
- Star
- 5.1k
- Fork
- 1.1k
- Merge trung bình
- 2 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 27
Mô tả
Hi! It seems the openapi connector is not setting the correct TS type when setting true the nullable flag
For example, with the following JSON OpenAPI definition model:
"TestObject": {
"type": "object",
"properties": {
"name": {
"type": "string",
"nullable": true,
"default": null,
"description": "Test property",
"example": null
},
It creates a model with the following property:
@property({jsonSchema: {
type: [
'string',
'null',
],
default: null,
description: 'Specific endpoint for this queue, if not specified, the generic endpoint for this service will be used',
}})
endpoint?: string = null;
Obviously, as endpoint is set as string, it throws a TS Check error in build time:
error TS2322: Type 'null' is not assignable to type 'string | undefined'.
Why isn't setting the property type correctly, whereas in the type annotation seems to be aware of it?
Thanks!
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách lần theo quá trình tạo model TypeScript của connector OpenAPI cho một thuộc tính có nullable: true và default: null. So sánh annotation của thuộc tính được tạo với kiểu đã khai báo của nó, sau đó chạy các bước kiểm tra tạo model liên quan hoặc bản build TypeScript; hoàn thành khi các thuộc tính nullable chấp nhận null mà không có TS2322.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- openapi, typescript
- Lĩnh vực
- api
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 38/100