From 1189143b3a150997d3e2a41678e405fd8836a407 Mon Sep 17 00:00:00 2001 From: sharpchen Date: Thu, 28 Nov 2024 21:26:39 +0800 Subject: [PATCH] main --- .../JavaScript/docs/Type System/Array.md | 0 .../JavaScript/docs/Type System/Function.md | 0 .../JavaScript/docs/Type System/Object.md | 0 .../docs/Type System/Primitive Types.md | 0 .../docs/Object Manipulation/Measure.md | 3 ++ .../Type Transformation/Conditional Keys.md | 38 +++++++++++++++++++ docs/services/DocumentService.ts | 2 +- docs/services/SidebarService.ts | 2 +- 8 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 docs/document/JavaScript/docs/Type System/Array.md create mode 100644 docs/document/JavaScript/docs/Type System/Function.md create mode 100644 docs/document/JavaScript/docs/Type System/Object.md create mode 100644 docs/document/JavaScript/docs/Type System/Primitive Types.md create mode 100644 docs/document/Powershell/docs/Object Manipulation/Measure.md create mode 100644 docs/document/TypeScript/docs/Type Transformation/Conditional Keys.md diff --git a/docs/document/JavaScript/docs/Type System/Array.md b/docs/document/JavaScript/docs/Type System/Array.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/document/JavaScript/docs/Type System/Function.md b/docs/document/JavaScript/docs/Type System/Function.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/document/JavaScript/docs/Type System/Object.md b/docs/document/JavaScript/docs/Type System/Object.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/document/JavaScript/docs/Type System/Primitive Types.md b/docs/document/JavaScript/docs/Type System/Primitive Types.md new file mode 100644 index 00000000..e69de29b diff --git a/docs/document/Powershell/docs/Object Manipulation/Measure.md b/docs/document/Powershell/docs/Object Manipulation/Measure.md new file mode 100644 index 00000000..8ea7afaa --- /dev/null +++ b/docs/document/Powershell/docs/Object Manipulation/Measure.md @@ -0,0 +1,3 @@ +# Measure + + diff --git a/docs/document/TypeScript/docs/Type Transformation/Conditional Keys.md b/docs/document/TypeScript/docs/Type Transformation/Conditional Keys.md new file mode 100644 index 00000000..3138d888 --- /dev/null +++ b/docs/document/TypeScript/docs/Type Transformation/Conditional Keys.md @@ -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 = { + [ in as ]: +} +``` + +## 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 = keyof { + [K in keyof T as T[K] extends object ? never : K]: any // [!code highlight] +} + +type SingularKeyOfFoo = KeyOfSingularTypedProperty +``` + diff --git a/docs/services/DocumentService.ts b/docs/services/DocumentService.ts index f5506e78..ecb5e3e4 100644 --- a/docs/services/DocumentService.ts +++ b/docs/services/DocumentService.ts @@ -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: '' }, diff --git a/docs/services/SidebarService.ts b/docs/services/SidebarService.ts index 1d830ab9..bcfdc626 100644 --- a/docs/services/SidebarService.ts +++ b/docs/services/SidebarService.ts @@ -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}`), };