1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TypeORMでDate型使えない問題

Last updated at Posted at 2023-12-06

環境

Typescript 4.5.2
Express 4.16.1
TypeORM 0.3.17
postgreSQL 15

状況

TypeORMのEntityでnullableなDate型を定義したいのですが、以下のコードでエラーが出ました。

@Column({ nullable: true, type: "Date" })
  time!: Date|null;
エラー内容
TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type '{ nullable: boolean; type: string; }' is not assignable to parameter of type '(type?: any) => Function'.
      Object literal may only specify known properties, and 'nullable' does not exist in type '(type?: any) => 
Function'.

20   @Column({ nullable: true, type: "Date" })

ここで調査してみると、TypeORMにはDate型はなく、string型で表現されるらしいです。
https://github.com/typeorm/typeorm/issues/2176

そこでstring型に変更しましたがまたエラーが出ます。

TypeORM connection error:  
DataTypeNotSupportedError: Data type "Object" in "Schedule.time" is not supported by "postgres" database.

これについてはこれと同じくtype:'varchar'を明示してあげることでうまくいきました。
https://stackoverflow.com/questions/64350794/typeorm-message-data-type-object-in-is-not-supported-by-postgr

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?