Skip to content

Commit 1189143

Browse files
committed
main
1 parent e7ed2e1 commit 1189143

File tree

8 files changed

+43
-2
lines changed

8 files changed

+43
-2
lines changed

docs/document/JavaScript/docs/Type System/Array.md

Whitespace-only changes.

docs/document/JavaScript/docs/Type System/Function.md

Whitespace-only changes.

docs/document/JavaScript/docs/Type System/Object.md

Whitespace-only changes.

docs/document/JavaScript/docs/Type System/Primitive Types.md

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Measure
2+
3+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Conditional Keys
2+
3+
Instead of iterating over all properties/entries in a type, we can do the following before we transform the target types.
4+
5+
- Filter keys: filter out keys that we don't want to include base on a conditional type expression.
6+
- Transform keys: transform keys before we transform traget type.
7+
8+
## Synopsis
9+
10+
`as` keyword was introduced here to connect with conditional type expression.
11+
12+
```ts
13+
type <name> = {
14+
[<type> in <type> as <condition>]: <type>
15+
}
16+
```
17+
18+
## Filter Keys
19+
20+
The following example shows how to extract property names that're not singular typed(not an object or a collection).
21+
All keys that didn't satisfies the condition `T[K] extends object` will be replaced as `never`, which is the empty type. In other words, they will be filtered.
22+
And lastly the target type can be arbitrary since we don't need it, all we need is the keys.
23+
24+
```ts twoslash
25+
const foo = {
26+
bar = 123,
27+
baz = '123',
28+
goo = [1, 2, 3],
29+
foo = { foo = {} }
30+
}
31+
32+
type KeyOfSingularTypedProperty<T> = keyof {
33+
[K in keyof T as T[K] extends object ? never : K]: any // [!code highlight]
34+
}
35+
36+
type SingularKeyOfFoo = KeyOfSingularTypedProperty<typeof foo>
37+
```
38+

docs/services/DocumentService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const documentMap = {
1414
Docker: { icon: '🐳', description: 'Ultimate Docker' },
1515
Git: { icon: '😸', description: 'Git mastery' },
1616
JavaScript: { icon: '😅', description: '' },
17-
SQL: { icon: '🦭', description: '' },
17+
// SQL: { icon: '🦭', description: '' },
1818
TypeScript: { icon: '🤯', description: '' },
1919
// VBA: { icon: '💩', description: 'VBA for excel' },
2020
// Vue3: { icon: '⚡', description: '' },

docs/services/SidebarService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SidebarService implements ISidebarService {
5353
if (Object.prototype.hasOwnProperty.call(subs, index)) {
5454
const sub = subs[index];
5555
const currentSidebarItem: DefaultTheme.SidebarItem = {
56-
collapsed: false,
56+
collapsed: true,
5757
text: solveSharpSign(sub.name.replace(/^\d+\.\s*/, '')), // remove leading index
5858
items: this.transformFolderToSidebarItem(sub, `${base}/${folder.name}`),
5959
};

0 commit comments

Comments
 (0)