你好世界 - 开始使用

阅读时间: 2 分钟 字数: 268

欢迎来到我们的增强博客!这是一篇展示新功能和改进内容结构的示例文章。

示例封面图片

示例封面图片

你好世界 - 开始使用

欢迎来到我们的增强博客!这篇文章演示了我们实现的新内容结构和改进功能。

新功能介绍

这个博客现在包含:

  • 增强的SEO:更好的元标签、结构化数据和社交媒体优化
  • 响应式设计:移动优先的布局,在所有设备上都看起来很棒
  • 改进的开发体验:使用模板和工具轻松创建内容
  • 更好的内容管理:分类、标签、阅读时间等功能

功能展示

这是一张本地图片,用于测试我们的图片处理:

本地图片

开始使用

要创建新文章,使用以下命令:

npm run new-post -- --title "我的新文章" --type article --lang zh

这将生成一篇包含所有正确前置数据字段配置的新文章。

TypeScript 示例

这是一个 TypeScript 代码示例:

// 使用 'typeof' 推断类型
const person = { name: "Alice", age: 30 };
type PersonType = typeof person; // { name: string; age: number }

// 'satisfies' 确保类型匹配但允许更具体的类型
type Animal = { name: string };
const dog = { name: "Buddy", breed: "Golden Retriever" } satisfies Animal;

// 带有 'extends' 和默认值的泛型
function identity<T extends number | string = string>(arg: T): T {
  return arg;
}

let str = identity(); // 默认类型是 string
let num = identity(42); // T 推断为 number

总结

这个增强的博客系统为内容创作者提供了更好的工具和更丰富的功能。

Second

// Using 'typeof' to infer types
const person = { name: "Alice", age: 30 };
type PersonType = typeof person; // { name: string; age: number }

// 'satisfies' to ensure a type matches but allows more specific types
type Animal = { name: string };
const dog = { name: "Buddy", breed: "Golden Retriever" } satisfies Animal;

// Generics with 'extends' and default values
function identity<T extends number | string = string>(arg: T): T {
  return arg;
}

let str = identity(); // Default type is string
let num = identity(42); // T inferred as number

// 'extends' with interface and class
interface HasLength {
  length: number;
}

function logLength<T extends HasLength = string>(arg: T): void {
  console.log(arg.length);
}

logLength("Hello"); // OK: string has length (default is string)
logLength([1, 2, 3]); // OK: array has length
// logLength(123);      // Error: number doesn't have length

// 'typeof' with functions
function add(x: number, y: number): number {
  return x + y;
}

type AddFunctionType = typeof add; // (x: number, y: number) => number

// Generic interfaces with 'extends' and default types
interface Box<T extends object = { message: string }> {
  content: T;
}

let defaultBox: Box = { content: { message: "Hello" } }; // Uses default type
let customBox: Box<{ status: number }> = { content: { status: 200 } };

// Complex example with 'satisfies' and default generics
type Task = {
  title: string;
  description?: string;
  completed: boolean;
};

const myTask = {
  title: "Learn TypeScript",
  completed: false,
  priority: "High",
} satisfies Task; // Allows priority but ensures Task structure

// Generic function with default type
function wrapInArray<T = string>(value: T): T[] {
  return [value];
}

const stringArray = wrapInArray(); // Default to string
const numberArray = wrapInArray(42); // T inferred as number

/**
 * Combines two generic types into a tuple.
 *
 * @template T - The first type.
 * @template U - The second type.
 * @param {T} first - The first value.
 * @param {U} second - The second value.
 * @returns {[T, U]} A tuple containing both values.
 */
function combine<T, U>(first: T, second: U): [T, U] {
  return [first, second];
}
TOC