2
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?

TypeScriptでクラスを書くとTS1294: This syntax is not allowed when erasableSyntaxOnly is enabled.

2
Last updated at Posted at 2026-10-10

はじめに

  • なんとなくで書いたもので構文エラー。 他言語の書き方だったかも
    • →コメントで教えていただきました。 提示いただいた参考記事 のとおり、 erasableSyntaxOnly フラグで禁止されるもののようです
    • IDEでも警告が出ていました :bow:

スクリーンショット 2026-10-13 19.51.50.png

問題

  • この書き方エラー
export class Todo {
  constructor(
    public id: string,
    public title: string,
    public done: boolean,
    public created_at: string,
  ) {}
}

解決

  • こちらではエラーが出ない
export class Todo {
  id: string;
  title: string;
  done: boolean;
  created_at: string;

  constructor(id: string, title: string, done: boolean, created_at: string) {
    this.id = id;
    this.title = title;
    this.done = done;
    this.created_at = created_at;
  }
}

終わりに

2
0
3

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
2
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?