TypeScript
What is TypeScript?
TypeScript vs. JavaScript
Current Uses of TypeScript
// Example of integrating TypeScript with a webpage
// Define an interface for a user
interface User {
name: string;
age: number;
}
// A function that takes a User object and returns a greeting message
function greetUser(user: User): string {
return `Hello, ${user.name}! You are ${user.age} years old.`;
}
// Creating a User object
const user: User = {
name: "John Doe",
age: 30
};
// Using the function and displaying the greeting in the webpage
document.body.innerHTML = greetUser(user);Last updated
Was this helpful?