Naming of TypeScript s union and intersection types

0 votes
The logic behind the words union types and intersection types in TypeScript is beyond me.

If the properties of distinct types are sets of properties, the final type will be the union of those sets if I combine them with the & operator. Following that rationale, I believe types like these should be referred to as union types. I can only use the common properties of them when I join them with |, which is the intersection of the sets.
Jun 10 in TypeSript by Logan
• 2,140 points
10 views

1 answer to this question.

0 votes

The type A | B refers to objects which are either A or B. In other words, values of such type are drawn from the union of values for A and values for B.

The type A & B refers to objects which are both A and B. In other words, values of such type are drawn from the intersection of values for A and values for B.

The naming and semantics are identical in other languages such as C++.

answered Jun 10 by Nina
• 3,020 points

Related Questions In TypeSript

0 votes
0 answers

Typescript says: "types '"a"' and '"b"' have no overlap". What does it mean?

const value = Math.random() < 0.5 ? ...READ MORE

Jul 5 in TypeSript by Logan
• 2,140 points
10 views
0 votes
0 answers

In typescript, why do the | and & operators flip their meaning when used on function types?

In this code, example1 and example2 are confusing me: type F1 = ...READ MORE

Jul 13 in TypeSript by Logan
• 2,140 points
25 views
0 votes
0 answers

Typescript: Changing the definition of some third party types d.ts

I am a little bit lost how ...READ MORE

Jul 18 in TypeSript by Logan
• 2,140 points
10 views
0 votes
0 answers

What is TypeScript and why would I use it in place of JavaScript?

Can you please describe what the TypeScript ...READ MORE

Jul 18 in TypeSript by Logan
• 2,140 points
11 views
0 votes
1 answer

TypeScript - ',' expected.ts(1005)

You can't put statements in JSX curly braces, only expressions. You ...READ MORE

answered Jun 9 in TypeSript by Nina
• 3,020 points
628 views
0 votes
1 answer

How to use useState hook in React with TypeScript correctly?

Without any initial argument, the type of email and setEmail will ...READ MORE

answered Jun 10 in TypeSript by Nina
• 3,020 points
46 views
0 votes
0 answers

Create a react app react 18 with typescript

I am trying to create react 18 ...READ MORE

Jul 5 in TypeSript by Logan
• 2,140 points
10 views
0 votes
1 answer

Cannot access web3 object with typescript and ethereum

You still need to instantiate it first. ...READ MORE

answered Sep 25, 2018 in Blockchain by slayer
• 29,310 points
1,861 views
0 votes
1 answer

Conversion from both keys and values of object

You could just change the declaration of ...READ MORE

answered May 31 in TypeSript by Nina
• 3,020 points
16 views
0 votes
1 answer

What is TypeScript and why would I use it in place of JavaScript?

TypeScript is a superset of JavaScript which primarily ...READ MORE

answered May 31 in TypeSript by Nina
• 3,020 points
13 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP