# TypeAssert

`Util.``TypeAssert`()
  TypeAssert(_x: T): void

  This purpose of this function is guarantee a value is of a given type.

  This is essentially a compile time `console.assert(x instanceof T)`.

  This function is useful when terminating a type-narrowing if-else chain in that this function makes the code more robust to future type changes.

  Warning:

  `T=never` doesn’t appear to work properly, hence the existence of `TypeAssertNever`.

  Example:

      declare const x: Foo | Bar;
      if (x instanceof Foo) {
          console.log("foo");
      }
      else {
          // This becomes a compiler error if, for example, `x`'s type gets changed to add `Baz`:
          //    x: Foo | Bar | Baz
          TypeAssert<Bar>(x);
          console.log("bar");
      }

  Parameters

  > _x: T

  Returns: void

Conversation saved
HOOPSY BETA

### Hello! I'm HOOPSY

Your Docs generative AI assistant. Ask me anything about HOOPS Visualize Web or choose a sample question below to start a conversation:

What is HOOPS Visualize Web?
What are the latest release notes for HOOPS Visualize Web?
How do I start evaluating HOOPS Visualize Web?
How do I write my first sample application?
How can I get assistance?

HOOPSY may store conversations according to OpenAI's policy. Responses may not always be accurate.

HOOPSY is thinking...