Skip to content

how to determine whether an unknown variable is a specific Record / Tuple #388

Open
@eczn

Description

@eczn
let p = #{ x: 11, y: 22 }

function handlePoint(x: unknown) {
  if (x instanceof /* ??? */) {  // how to determine whether an unknown variable is a specific Record / Tuple
    console.log(`x is a point:`, x)
  } else {
    throw new Error(`x is not a point`)
  }
}

try to name #{ x, y }:

record Point #{ x, y }
const p = Point #{ x: 1, y: 2 }
x instanceof Point

or:

x instanceof #{x, y} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions