static_cast
v1.0.1
Published
Purely for getting correct type hints during development!
Readme
static_cast
Function static_cast that allows you to narrow the type of a value. It does nothing at runtime.
For more awesome packages, check out my homepage💛
static_castis a tribute to C++.
Usage
When you need it ?
Some times we use custom methods to identify the correct type of some value.
// element is some kind of input element.
if (element.tagName === 'INPUT'){
static_cast<HTMLInputElement>(element);
element.value = xxx; // now use element as a HTMLInputElement
} else if (element.tagName === 'SELECT'){
static_cast<HTMLSelectElement>(element);
element.value = xxx;
}Tree Shaking
Since "sideEffects": false, these static_cast calls can be safely removed during tree shaking.
License
MIT
