sdasdasd in typescript

To create a function with typed parameters in TypeScript, you can define an interface for the parameter type or use a built-in type such as number, string, or boolean.

Here's an example of a TypeScript function with an interface for its parameter:

index.ts
interface Person {
  name: string;
  age: number;
}

function greet(person: Person) {
  console.log(`Hello, ${person.name}! You are ${person.age} years old.`);
}
162 chars
9 lines

In the example above, we define an interface Person with two properties: name of type string and age of type number. Then, we declare a function greet that takes a parameter of type Person.

You can call the greet function with an object that conforms to the Person interface like this:

index.ts
const jane: Person = { name: 'Jane', age: 25 };

greet(jane); // logs "Hello, Jane! You are 25 years old."
107 chars
4 lines

Note that TypeScript will throw an error if you try to call greet with an object that does not have the required properties of the Person interface.

gistlibby LogSnag