function getColors(
url: string,
config: Config
): Promise<Result>;
}
type Config = {
dominant?: boolean;
average?: boolean;
};
type Result = {
dominant?: string;
average?: string;
};
How can I say if dominant was passed as true to the config object e.g. getColors(url, {
dominant: true}) then it is not optional in Result.
async () => {
let example : string;
const colors = await getColors(url, {dominant: true});
example = colors.dominant;
// ^^^^^^ Type 'string | undefined' is not assignable to type 'string'.
// Type 'undefined' is not assignable to type 'string'
};