Created
February 7, 2025 14:42
-
-
Save Kcko/ca8fbfcc701e6a17f76ab3f860ecb4d4 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