-
Notifications
You must be signed in to change notification settings - Fork 0
Object Types
Jorge Castro edited this page Nov 10, 2025
·
1 revision
function printFullName(person: { firstName: string; lastName: string }) {
console.log("Full Name: " + person.firstName + " " + person.lastName);
}
printFullName({ firstName: "John", lastName: "Doe" });Look at the ? beside lastName
function printFullName(person: { firstName: string; lastName?: string }) {
const fullName = `${person.firstName} ${person.lastName}`;
console.log("Full Name: " + fullName.trim());
}
printFullName({ firstName: "John", lastName: "Doe" });
printFullName({ firstName: "Alice" });'person.lastName' is possibly 'undefined' here
function printNamesUppercase(person: { firstName: string; lastName?: string }) {
console.log(person.firstName.toUpperCase());
console.log(person.lastName.toUpperCase());
}
printNamesUppercase({ firstName: "John", lastName: "Doe" });
printNamesUppercase({ firstName: "Alice" });- Sync-Obsidian-with-GitHub-on-iOS
- Obsidian-community-plugins
- Optimizing-Novel-Word-Count-Plugin-for-Git-Users
- What is TypeScript, and why you should use it
- Quick setup
- Inference and type annotations
- Fundamental Types
- Object Types
- Union Types
- Type Aliases and Interfaces
- Type Assertions
- Literal Types
- null and undefined
- Narrowing
- Creating Types from Types
- Common Built‐in and Utility Types
- tsc CLI ‐ (The Compiler)
- Avoid using Object or {}
- Ignoring TypeScript errors
- TypeScript resources