Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created February 7, 2025 14:37
Show Gist options
  • Save Kcko/d7a581d7a7a9a770fb0aab8964a49e82 to your computer and use it in GitHub Desktop.
Save Kcko/d7a581d7a7a9a770fb0aab8964a49e82 to your computer and use it in GitHub Desktop.
// 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