Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions example/typescript/components/Hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface GreetingProps {
name: string
}

function Hello({ name }: GreetingProps): string {
return `Hello, ${name}!`
}

export default Hello
27 changes: 27 additions & 0 deletions example/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Hello from '@/components/Hello'
import { formatDate, add } from '@/utils'

const app = document.getElementById('app')

if (app) {
const greeting = Hello('TypeScript')
const today = formatDate(new Date())
const sum = add(2, 3)

app.innerHTML = `
<div style="font-family: Arial, sans-serif; padding: 20px;">
<h1 style="color: #333;">${greeting}</h1>
<p style="color: #666;">Today is: ${today}</p>
<p style="color: #666;">2 + 3 = ${sum}</p>
<p style="color: #888; font-size: 14px; margin-top: 30px;">
This is a TypeScript example using:
<ul>
<li>ts-loader for compilation</li>
<li>tsconfig.json for configuration</li>
<li>Path aliases (@/components, @/utils)</li>
<li>ForkTsCheckerWebpackPlugin for type checking</li>
</ul>
</p>
</div>
`
}
29 changes: 29 additions & 0 deletions example/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "ES2015",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"declaration": false,
"sourceMap": true,
"noEmit": true,
"lib": ["DOM", "DOM.Iterable", "ES2015"],
"baseUrl": ".",
"paths": {
"@/*": ["./*"]
},
"ignoreDeprecations": "6.0"
},
"include": [
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules",
"dist"
]
}
11 changes: 11 additions & 0 deletions example/typescript/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function formatDate(date: Date): string {
return date.toLocaleDateString('zh-CN', {
year: 'numeric',
month: 'long',
day: 'numeric'
})
}

export function add(a: number, b: number): number {
return a + b
}
Loading