Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpchen committed Nov 28, 2024
1 parent e7ed2e1 commit 1189143
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 2 deletions.
Empty file.
Empty file.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions docs/document/Powershell/docs/Object Manipulation/Measure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Measure


Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Conditional Keys

Instead of iterating over all properties/entries in a type, we can do the following before we transform the target types.

- Filter keys: filter out keys that we don't want to include base on a conditional type expression.
- Transform keys: transform keys before we transform traget type.

## Synopsis

`as` keyword was introduced here to connect with conditional type expression.

```ts
type <name> = {
[<type> in <type> as <condition>]: <type>
}
```

## Filter Keys

The following example shows how to extract property names that're not singular typed(not an object or a collection).
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.
And lastly the target type can be arbitrary since we don't need it, all we need is the keys.

```ts twoslash
const foo = {
bar = 123,
baz = '123',
goo = [1, 2, 3],
foo = { foo = {} }
}

type KeyOfSingularTypedProperty<T> = keyof {
[K in keyof T as T[K] extends object ? never : K]: any // [!code highlight]
}

type SingularKeyOfFoo = KeyOfSingularTypedProperty<typeof foo>
```
2 changes: 1 addition & 1 deletion docs/services/DocumentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const documentMap = {
Docker: { icon: '🐳', description: 'Ultimate Docker' },
Git: { icon: '😸', description: 'Git mastery' },
JavaScript: { icon: '😅', description: '' },
SQL: { icon: '🦭', description: '' },
// SQL: { icon: '🦭', description: '' },
TypeScript: { icon: '🤯', description: '' },
// VBA: { icon: '💩', description: 'VBA for excel' },
// Vue3: { icon: '⚡', description: '' },
Expand Down
2 changes: 1 addition & 1 deletion docs/services/SidebarService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SidebarService implements ISidebarService {
if (Object.prototype.hasOwnProperty.call(subs, index)) {
const sub = subs[index];
const currentSidebarItem: DefaultTheme.SidebarItem = {
collapsed: false,
collapsed: true,
text: solveSharpSign(sub.name.replace(/^\d+\.\s*/, '')), // remove leading index
items: this.transformFolderToSidebarItem(sub, `${base}/${folder.name}`),
};
Expand Down

0 comments on commit 1189143

Please sign in to comment.