You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -68,17 +69,17 @@ This behavior is _nearly_ equivalent to if we had:
68
69
69
70
```ts
70
71
interfaceUser {
71
-
name:string;
72
-
age:number|undefined;
72
+
name:string;
73
+
age:number|undefined;
73
74
}
74
75
```
75
76
76
77
The difference is whether the key must be explicitly provided by objects wanting to satisfy this interface:
77
78
78
79
```ts
79
80
interfaceUser {
80
-
name:string;
81
-
age:number|undefined;
81
+
name:string;
82
+
age:number|undefined;
82
83
}
83
84
84
85
// Type error! "age" is a required property of "User"
@@ -106,7 +107,7 @@ The only difference is that `||` will fall back if the lefthand value is _anythi
106
107
107
108
I highly recommend forgetting about `||` for default fallbacks and using `??` instead.
108
109
109
-
You can enforce this with [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint)'s own [prefer-nullish-coalescing](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md) rule
110
+
You can enforce this with [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint)'s own [prefer-nullish-coalescing](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.mdx) rule
110
111
111
112
## Optional Chaining (?.)
112
113
@@ -116,15 +117,15 @@ What if this time we have a `Session` object, which has a `User` only if the cur
116
117
117
118
```ts
118
119
interfaceSession {
119
-
user?:User;
120
+
user?:User;
120
121
}
121
122
122
123
function getWelcomeMessage(session:Session) {
123
-
const userName =session.user?.name;
124
-
if (userName===undefined) {
125
-
return"Hello Guest!";
126
-
}
127
-
return`Hello ${userName}!`;
124
+
const userName =session.user?.name;
125
+
if (userName===undefined) {
126
+
return"Hello Guest!";
127
+
}
128
+
return`Hello ${userName}!`;
128
129
}
129
130
```
130
131
@@ -142,12 +143,12 @@ We can use all these concepts together:
0 commit comments