function addNumbers(a: number, b: number): number {
return a + b
}
export default addNumbers
export const addStrings = (str1: string, str2: string) => `${str1}${str2}`
export const format = (title: string, params: string | number) => `${title}${params}`
export const printFormat = (title: string, params: string | number): void => {
console.log(format(title, params));
}
export const fetchData = (url: string): Promise<string> => Promise.resolve(`Data fetch ${url}`)
function introduce(salutation: string, ...names: string[]): string {
return `${salutation} ${names.join(" ")}`
}
export function getName(user: { first: string; last: string }): string {
return `${user?.first ?? 'first'},${user?.last ?? 'last'}`
}
export function printToFile(text: string, callback: () => void): void {
console.log(text);
callback()
}
type MutationFunction = (v: number) => number
export function arrayMutate(numbers: number[], mutate: MutationFunction): number[] {
return numbers.map(mutate)
}
const myMutationFunction: MutationFunction = (a: number) => a
console.log(arrayMutate([1, 2, 3], (v) => v * 10));
type adderFunction = (val: number) => number
export function createAdder(num: number): adderFunction {
return (val: number) => num + val
}
const addOne = createAdder(1)
console.log(addOne(2));