EasyJavaScriptTypeScript
Type Annotations — Functions & Objects
TypeScriptTypesBasics
Add explicit TypeScript annotations to make the following functions type-safe.
Implement three functions:
1. `greet(name)` — accepts a string, returns a string greeting "Hello, {name}!".
2. `add(a, b)` — accepts two numbers, returns their number sum.
3. `getFullName(user)` — accepts an object with firstName: string and lastName: string, returns a string "{firstName} {lastName}".
Examples
greet("Alice")→"Hello, Alice!"add(3, 4)→7getFullName({ firstName: "Jane", lastName: "Doe" })→"Jane Doe"
Sample tests
Test #1greet — basic name
Input: ["greet","Alice"]
Output: "Hello, Alice!"
Test #2greet — World
Input: ["greet","World"]
Output: "Hello, World!"
Test #3add — 3 + 4
Input: ["add",3,4]
Output: 7
Test #4add — negative + positive
Input: ["add",-1,1]
Output: 0
Test #5getFullName — basic
Input: ["getFullName",{"lastName":"Doe","firstName":"Jane"}]
Output: "Jane Doe"