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, 2022 in TypeSript by Logan
• 2,140 points
250 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++.

If you need to know more about React, Its recommended to join React JS Online Course today.

answered Jun 10, 2022 by Nina
• 3,060 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, 2022 in TypeSript by Logan
• 2,140 points
5,944 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, 2022 in TypeSript by Logan
• 2,140 points
319 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, 2022 in TypeSript by Logan
• 2,140 points
803 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, 2022 in TypeSript by Logan
• 2,140 points
196 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, 2022 in TypeSript by Nina
• 3,060 points
13,116 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, 2022 in TypeSript by Nina
• 3,060 points
1,673 views
0 votes
0 answers

Create a react app react 18 with typescript

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

Jul 5, 2022 in TypeSript by Logan
• 2,140 points
665 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,350 points
2,657 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, 2022 in TypeSript by Nina
• 3,060 points
246 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, 2022 in TypeSript by Nina
• 3,060 points
316 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP