sindresorhus / is

Type check values
MIT License
1.68k stars 109 forks source link

Make the `is()` function type-safe #117

Closed bjornstar closed 4 years ago

bjornstar commented 4 years ago

This is the functional change that was removed from #113

There was an unsafe cast in getObjectType which could allow any string to be returned. This was used as an output in the primary is function.

The primary function is now always returns a TypeName.

The other breaking change here is the return value of HTMLElement for dom elements like div or span. Previously it would return HTMLDivElement or HTMLSpanElement, but now they all return HTMLElement.

sindresorhus commented 4 years ago

The other breaking change here is the return value of HTMLElement for dom elements like div or span. Previously it would return HTMLDivElement or HTMLSpanElement, but now they all return HTMLElement.

Can you elaborate on why we should change this? What's the benefit of just returning HTMLElement?

bjornstar commented 4 years ago

The other breaking change here is the return value of HTMLElement for dom elements like div or span. Previously it would return HTMLDivElement or HTMLSpanElement, but now they all return HTMLElement.

Can you elaborate on why we should change this? What's the benefit of just returning HTMLElement?

The current type guard is written for the HTMLElement type so it's consistent with what is implemented.

To be considered type safe for all 119 HTML tags would require a significant increase to the size and scope of the project.

sindresorhus commented 4 years ago

Thanks :)

Released: https://github.com/sindresorhus/is/releases/tag/v3.0.0