loopbackio / loopbackio/loopback-next
Invalid TS models when properties are nullable
まだ誰も着手していません。
- 主要言語
- TypeScript
- スター
- 5.1k
- フォーク
- 1.1k
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 27
説明
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!
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、nullable: true と default: null を持つプロパティについて、OpenAPI コネクターの TypeScript モデル生成を追跡します。生成されたプロパティのアノテーションを宣言された型と比較し、その後、関連するモデル生成のチェックまたは TypeScript ビルドを実行します。nullable プロパティが TS2322 なしで null を受け入れれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- openapi, typescript
- 領域
- api
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100