Syntax

TypeScript Narrow with in Syntax

In TypeScript, narrow with in: narrows by checking for a property — if ("swim" in animal) { ... }

Quick Answer

Syntax
if ("swim" in animal) { ... }
TypeScriptSyntax

Narrow with in

Code example
if ("swim" in animal) { ... }

Narrows by checking for a property.

Learn More

How to narrow with in in TypeScript

  1. Open your TypeScript file or editor.
  2. Copy the example, then replace its sample names and values for your code.

TypeScript Narrow with in Syntax

Use if ("swim" in animal) { ... }.

Related Syntax References

Frequently asked questions

What is the TypeScript syntax for narrow with in?

Use this pattern: if ("swim" in animal) { ... }

Can I copy this TypeScript code example?

Yes. Use Copy code and adapt the example to your program.

Is this TypeScript syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify