A function is a promise. It takes something, does something, and returns something. Learn how TypeScript makes those promises explicit — and how reading function signatures is just reading English contracts.
函数是一种承诺。它接收某物,做某件事,然后返回某物。本课学习如何阅读 TypeScript 函数签名——这就像阅读一份英文合同。
Read the Code
// A function signature tells you a complete story in one line:
// WHO takes WHAT and returns WHAT
function greetUser(name: string): string {
return `Hello, ${name}! Welcome to TypeSpeak.`;
}
// 📖 Reading this signature in English:
// 'greetUser receives a name (string) and returns a greeting (string)'
// Functions with multiple parameters read like a recipe:
function calculateReadingTime(
wordCount: number,
wordsPerMinute: number = 200 // default value = assumption
): number {
return Math.ceil(wordCount / wordsPerMinute);
}
// Arrow functions — same idea, more concise:
const capitalize = (word: string): string =>
word.charAt(0).toUpperCase() + word.slice(1);
💡 Tip: read each line aloud in English. The comments are your guide.
Vocabulary Focus
parameter
/pəˈræmɪtər/
noun
参数(函数定义中的输入项)
argument
/ˈɑːrɡjəmənt/
noun
实参(调用函数时传入的具体值)
return type
/rɪˈtɜːrn taɪp/
noun phrase
返回类型(函数输出的数据类型)
concise
/kənˈsaɪs/
adjective
简洁的,言简意赅的
Comprehension Check
Answer in your head first — then reveal to see the model answer.
Q1: What does the `: string` after `greetUser(name: string)` mean?
Q2: What is the difference between a parameter and an argument?
Key Insight▼ Reveal