6

I was studing Typescript, but I have some confusion.

type t = number & string // never
type t1 = number & boolean // never
type t2 = number & string[] // number & string[]

Why does it look different?

Drag13
  • 5,859
  • 1
  • 18
  • 42
clencat
  • 149
  • 3
  • 2
    Does this answer your question? [Intersection types with Typescript](https://stackoverflow.com/questions/64614085/intersection-types-with-typescript) – andy mccullough Dec 21 '21 at 08:22

1 Answers1

2

In Typescipt the instersection & of two primitive types is always never because a variabe cannot be both string and a number, but the intersection of two array/object is called as branded object and one array/object with a primitive is a valid type and is called as branded primitve , so where do we use branded primitive ? , refer the below example

type SomeUrl = string & {'this is a url': {}};

let x = <SomeUrl>'';
Goutham J.M
  • 1,726
  • 12
  • 25