Skip to content

Do not use a type assertion expression

Warren Gifford 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

Loading