Last active
April 6, 2020 02:39
-
-
Save yowchun93/f122fe890e52a0d7f30e4ecbf646040e to your computer and use it in GitHub Desktop.
Practising TS generics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a function which takes an array of any types, and return a value of that type | |
// create a function which takes 2 values of any type and return an array of the type | |
// create a function called 'makeFullName', which takes an object | |
// create a function called 'makeFullName', which takes an object with attribute { firstName, lastName } | |
// making it optional | |
interface UserName { | |
firstName: string | |
lastName: string | |
fullName?: string | |
} | |
// not sure how to make this work | |
const makeFullName = (obj: UserName): (obj: UserName) => { | |
return { | |
...obj, | |
fullName: obj.firstName + " " + obj.lastName | |
} | |
} | |
const yc = makeFullName({firstName: 'yap', lastName: 'yowchun'}) | |
console.log(yc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment