25

Can someone please explain the difference between Boolean and boolean in Typescript?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Yogesh Nikam
  • 443
  • 1
  • 4
  • 13

1 Answers1

39

Uppercase Boolean is an object type.

Lowercase boolean is a primitive type.

You should always use boolean (the primitive type in your programs). This is because, the Typescript type system does not force an object to its primitive type, while JavaScript does.

You shouldn't write:

function yourFunction(foo: Boolean)

But instead always write:

function yourFunction(foo: boolean)

For more info, see TypeScript Lang - Everyday Types

Joel
  • 5,732
  • 4
  • 37
  • 65