Created
February 7, 2025 14:37
-
-
Save Kcko/d7a581d7a7a9a770fb0aab8964a49e82 to your computer and use it in GitHub Desktop.
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
// union | |
type StringOrNumber = string | number; | |
// intersection | |
type User = { id: number }; | |
type Admin = { isAdmin: boolean }; | |
type AdminUser = User & Admin; // { id: number; isAdmin: boolean; } | |
// return type | |
type GetUserType = () => { id: number; name: string }; | |
type UserType = ReturnType<GetUserType>; // { id: number; name: string } | |
// return type pres interface | |
interface StringFormat { | |
(str: string, isUpper: boolean): string; | |
} | |
let format: StringFormat; | |
format = function (str: string, isUpper: boolean) { | |
return isUpper ? str.toLocaleUpperCase() : str.toLocaleLowerCase(); | |
}; | |
console.log(format('hi', true)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment