Skip to content

Instantly share code, notes, and snippets.

@bruno-sartori
Created August 24, 2024 15:09
Show Gist options
  • Save bruno-sartori/b2fe6e544870a35089240ac06f363dd8 to your computer and use it in GitHub Desktop.
Save bruno-sartori/b2fe6e544870a35089240ac06f363dd8 to your computer and use it in GitHub Desktop.
Clone interface with optional parameters but make them required
interface IOptionalPropertiesSubInterface {
width?: number;
height?: number;
opacity?: number;
lineHeight?: number;
}
interface IOptionalPropertiesInterface {
enabled?: boolean,
visual?: boolean,
propertyThatImplementsSubInterface?: IOptionalPropertiesSubInterface,
}
// Tipo auxiliar para tornar todas as propriedades obrigatórias e profundas
type DeepRequired<T> = {
[P in keyof T]-?: T[P] extends object
? T[P] extends (...args: any[]) => any
? T[P]
: DeepRequired<Required<T[P]>>
: T[P];
};
declare type IRequiredPropertiesSubInterface = DeepRequired<IOptionalPropertiesSubInterface>;
// Ajustando a configuração do logger para usar IRequiredContainerStyle para containerStyle
export declare type IRequiredPropertiesInterface = Omit<DeepRequired<IOptionalPropertiesInterface>, 'propertyThatImplementsSubInterface'> & {
propertyThatImplementsSubInterface: IRequiredPropertiesSubInterface;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment