Skip to content

Instantly share code, notes, and snippets.

@jrson83
Forked from wolak041/connectedTypes_1.ts
Created February 3, 2024 00:25
Show Gist options
  • Save jrson83/8032a62dda987057a267d2ee5bbd7fe8 to your computer and use it in GitHub Desktop.
Save jrson83/8032a62dda987057a267d2ee5bbd7fe8 to your computer and use it in GitHub Desktop.
interface Messenger {
sendText: () => void;
sendFile: () => void;
checkStatus?: () => void;
}
type RequiredFields<T> = {
[K in keyof T as T[K] extends Required<T>[K] ? K : never]: T[K];
};
// type RequiredMessengerProperties = {
// sendText: () => void;
// sendFile: () => void;
// }
type RequiredMessengerProperties = RequiredFields<Messenger>;
type FeatureOptions<T> = {
[K in keyof T as `is${Capitalize<K & string>}Enabled`]: boolean;
};
// type FeatureFlags = {
// isSendTextEnabled: boolean;
// isSendFileEnabled: boolean;
// }
type FeatureFlags = FeatureOptions<RequiredMessengerProperties>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment