Skip to content

Commit 010edc5

Browse files
committed
Fixed toggle props and added more to types deep dive
1 parent e74662a commit 010edc5

7 files changed

+85
-19
lines changed

src/04-advanced-components/29-toggle-props.problem.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
type EmbeddedPlaygroundProps =
2-
| {
3-
useStackblitz: true;
4-
stackblitzId: string;
5-
}
6-
| {
7-
useStackblitz?: false;
8-
codeSandboxId: string;
9-
};
1+
type EmbeddedPlaygroundProps = {
2+
useStackblitz?: boolean;
3+
stackblitzId?: string;
4+
codeSandboxId?: string;
5+
};
106

117
const EmbeddedPlayground = (props: EmbeddedPlaygroundProps) => {
128
if (props.useStackblitz) {
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import React from "react";
2-
31
/**
4-
* Try deleting each of these lines in the
5-
* types themselves:
2+
* Questions to answer:
63
*/
74

8-
// export = React;
9-
// export as namespace React;
5+
// 1. What is the React namespace?
6+
type Example = React.ReactNode;
7+
// ^?
108

11-
// What is ExoticComponent?
9+
/**
10+
* 2a. Most namespaces can't be used as values. So how come
11+
* we can use React as a value here?
12+
*/
13+
const element = React.createElement("div");
14+
// ^?
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,36 @@
1-
// Talk about JSX.Element return type
1+
/**
2+
* 1. What's the difference between JSX.Element,
3+
* React.ReactNode and React.ReactElement?
4+
*/
5+
const Component = () => {
6+
// ^?
7+
return <div>Hello world</div>;
8+
};
9+
10+
type ClickMe = React.ReactElement;
11+
type ClickMeToo = JSX.Element;
12+
type ClickMeThree = React.ReactNode;
13+
14+
/**
15+
* 2. Why does this break?
16+
*/
17+
18+
const Component2 = (): React.ReactNode => {
19+
return <div></div>;
20+
};
21+
22+
<>
23+
<Component2 />
24+
</>;
25+
26+
/**
27+
* 3. Why does this work?
28+
*/
29+
30+
const Component3 = (): React.ReactElement => {
31+
return <div></div>;
32+
};
33+
34+
<>
35+
<Component3 />
36+
</>;
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
export type JSXElementTypes = keyof JSX.IntrinsicElements;
1+
/**
2+
* 1. What is JSX.IntrinsicElements?
3+
*/
4+
5+
export type Example = React.JSX.IntrinsicElements;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<>
2+
<something id="123"></something>
3+
4+
{/* @ts-expect-error */}
5+
<something></something>
6+
7+
{/* @ts-expect-error */}
8+
<something id={123}></something>
9+
</>;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
declare global {
2+
namespace JSX {
3+
interface IntrinsicElements {
4+
"something-solution": {
5+
id: string;
6+
};
7+
}
8+
}
9+
}
10+
11+
<>
12+
<something-solution id="123"></something-solution>
13+
14+
{/* @ts-expect-error */}
15+
<something-solution></something-solution>
16+
17+
{/* @ts-expect-error */}
18+
<something-solution id={123}></something-solution>
19+
</>;

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
"skipLibCheck": true
1313
},
1414
"include": [
15-
"src"
15+
"src",
1616
]
1717
}

0 commit comments

Comments
 (0)