What is the difference between Boolean and boolean in Typescript?

Issue

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

Solution

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 – Basic Types

Answered By – Joel

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published