Skip to content
Snippets Groups Projects

Do not use a type assertion expression

Merged Administrator requested to merge github/fork/popmoore/patch-1 into master

Created by: popmoore

Do not use a type assertion expression for an object literal

Always prefer const x: T = { ... }; to const x = { ... } as T;. The type assertion in the latter case is either unnecessary or hides an error. The compiler will warn for excess properties with this syntax, but not missing required fields. For example: const x: { foo: number } = {} will fail to compile, but const x = {} as { foo: number } will succeed.

Merge request reports

Approval is optional

Merged by avatar (Jul 4, 2025 8:39am UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading