From 0139c9d9aeb604809c73d300dc18802845330bf7 Mon Sep 17 00:00:00 2001 From: MuntasirSZN Date: Tue, 14 Oct 2025 15:19:49 +0600 Subject: [PATCH] chore: add a test typescript file --- .../highlighted/Markdown/typescript.md | 57 +++++++++++++++++++ .../source/Markdown/typescript.md | 57 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 tests/syntax-tests/highlighted/Markdown/typescript.md create mode 100644 tests/syntax-tests/source/Markdown/typescript.md diff --git a/tests/syntax-tests/highlighted/Markdown/typescript.md b/tests/syntax-tests/highlighted/Markdown/typescript.md new file mode 100644 index 00000000..46239d39 --- /dev/null +++ b/tests/syntax-tests/highlighted/Markdown/typescript.md @@ -0,0 +1,57 @@ +# Typescript test + +```typescript +enum Status { + Pending, + InProgress, + Completed, +} + +interface Task { + id: number; + title: string; + status: Status; + assignee?: string; +} + +class TaskManager { + private tasks: T[] = []; + + addTask(task: T): void { + this.tasks.push(task); + } + + getTasksByStatus(status: Status): T[] { + return this.tasks.filter(task => task.status === status); + } + + async fetchTasks(): Promise { + // Simulate async fetch + return new Promise(resolve => setTimeout(() => resolve(this.tasks), 500)); + } +} + +// Type guard +function isTask(obj: any): obj is Task { + return typeof obj.id === 'number' && typeof obj.title === 'string'; +} + +// Usage +const manager = new TaskManager(); +manager.addTask({ id: 1, title: "Write docs", status: Status.Pending }); +manager.addTask({ id: 2, title: "Review PR", status: Status.InProgress, assignee: "Alice" }); + +(async () => { + const allTasks = await manager.fetchTasks(); + allTasks.forEach(task => { + if (isTask(task)) { + console.log(`Task #${task.id}: ${task.title} [${Status[task.status]}]`); + } + }); +})(); + +// Type assertion +const unknownValue: unknown = { id: 3, title: "Test", status: Status.Completed }; +const assertedTask = unknownValue as Task; +console.log(assertedTask.title); +``` diff --git a/tests/syntax-tests/source/Markdown/typescript.md b/tests/syntax-tests/source/Markdown/typescript.md new file mode 100644 index 00000000..e9efd63b --- /dev/null +++ b/tests/syntax-tests/source/Markdown/typescript.md @@ -0,0 +1,57 @@ +# Typescript test + +```typescript +enum Status { + Pending, + InProgress, + Completed, +} + +interface Task { + id: number; + title: string; + status: Status; + assignee?: string; +} + +class TaskManager { + private tasks: T[] = []; + + addTask(task: T): void { + this.tasks.push(task); + } + + getTasksByStatus(status: Status): T[] { + return this.tasks.filter(task => task.status === status); + } + + async fetchTasks(): Promise { + // Simulate async fetch + return new Promise(resolve => setTimeout(() => resolve(this.tasks), 500)); + } +} + +// Type guard +function isTask(obj: any): obj is Task { + return typeof obj.id === 'number' && typeof obj.title === 'string'; +} + +// Usage +const manager = new TaskManager(); +manager.addTask({ id: 1, title: "Write docs", status: Status.Pending }); +manager.addTask({ id: 2, title: "Review PR", status: Status.InProgress, assignee: "Alice" }); + +(async () => { + const allTasks = await manager.fetchTasks(); + allTasks.forEach(task => { + if (isTask(task)) { + console.log(`Task #${task.id}: ${task.title} [${Status[task.status]}]`); + } + }); +})(); + +// Type assertion +const unknownValue: unknown = { id: 3, title: "Test", status: Status.Completed }; +const assertedTask = unknownValue as Task; +console.log(assertedTask.title); +```