Skip to content

Commit

Permalink
feat(Type Guards): Allow typeGuards to work on undefined nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-ketch committed Aug 4, 2019
1 parent bc6ee68 commit 35a9ba7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ts/util/guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const is = <Ts extends Entity>(type: keyof TypeMap<Ts>) => {
*/
export const isA = <K extends keyof Types>(
type: K,
node: Node
node?: Node
): node is Types[K] => {
return isEntity(node) && node.type === type
}
Expand Down Expand Up @@ -103,7 +103,7 @@ export const isType = <K extends keyof Types>(type: K) => (
* @returns {(node is null | boolean | number | string)} Returns true if node is one of `null`, `boolean`, `string`, or `number`
*/
export const isPrimitive = (
node: Node
node?: Node
): node is null | boolean | number | string => {
const type = typeof node
if (node === null) return true
Expand Down Expand Up @@ -131,7 +131,7 @@ export const isEntity = (node?: Node): node is Entity => {
* @param {Node} node The node to get the type for
* @returns {(node is InlineNodesWithType)}
*/
export const isInlineEntity = (node: Node): node is InlineNodesWithType => {
export const isInlineEntity = (node?: Node): node is InlineNodesWithType => {
return typeof node === 'object' && isEntity(node)
? typeIs(inlineContentTypes)(node.type)
: false
Expand All @@ -142,7 +142,7 @@ export const isInlineEntity = (node: Node): node is InlineNodesWithType => {
* @param {Node} node The node to get the type for
* @returns {(node is InlineContent)}
*/
export const isInlineContent = (node: Node): node is InlineContent => {
export const isInlineContent = (node?: Node): node is InlineContent => {
return isPrimitive(node) || isInlineEntity(node)
}

Expand Down

0 comments on commit 35a9ba7

Please sign in to comment.