3.1.0-types.beta.2 • Published 8 years ago
rely-on v3.1.0-types.beta.2
Summary
HTML applications often require an identified element to be present and select the element with the assumption that it is present.
Type-annotation tools like TypeScript and Flow will let you know that this isn't strictly the case: if an element isn't present, then null will be returned from document.getElementById.
Refining the type of the result can be done in an if (element !== null)...else but this must be done every time in order to eliminate the possibility of null.
This package allows code to rely on a Node being present
- It refines a Node | null | undefinednode into aNodeto satisfy the type checker.
- It returns the Nodepassed so methods can chain as usual.
- It throws a TypeError with a customizable message if passed null | undefinedso missing elements are caught at the point of selection.
- It throws a TypeError if the argument passed is not a Node.
Example
const element = relyOn(document.getElementById('identifier'));3.1.0-types.beta.2
8 years ago
3.1.0-types.beta.1
8 years ago
3.0.1
8 years ago
3.0.0
8 years ago
2.1.0
8 years ago
2.0.1
8 years ago
2.0.0
8 years ago
1.0.1
8 years ago
1.0.0
8 years ago