Skip to content

Instantly share code, notes, and snippets.

@zcherries
Created November 9, 2018 01:47
Show Gist options
  • Save zcherries/a82e057992b270d164405fc85f5ee661 to your computer and use it in GitHub Desktop.
Save zcherries/a82e057992b270d164405fc85f5ee661 to your computer and use it in GitHub Desktop.
examples of typescript annotations
export type OptGroupNestedArrayTypes = Array<Array<string, Array<Array<string, string>>>>;
export type OptionGroupTypes = Array<{
groupLabel: string,
options: Array<{
label: string,
value: string,
}>,
}>;
export const getOptGroupChoicesFromNestedArrays = (
countries: OptGroupNestedArrayTypes,
): OptionGroupTypes => countries.map(item => ({
groupLabel: item[0],
options: item[1].map(choice => ({
label: choice[1],
value: choice[0],
})),
}));
type ValuesTypes = { country: string, };
export const isUSA = (values: ValuesTypes): boolean =>
constants.US_TERRITORIES.includes(values.country);
export const getGrossPayout = (
requestedQuantity: number = 0,
actualQuantity: number,
commonPrice: number,
): number => {
const quantity = requestedQuantity || Number(actualQuantity);
return Math.ceil(Number(commonPrice) * quantity * 100) / 100;
};
export const getExerciseCost = (
requestedQuantity: number,
actualQuantity: number,
exercisePrice: number = 0,
): number => {
const quantity = requestedQuantity || Number(actualQuantity);
return Math.ceil(Number(exercisePrice) * quantity * 100) / 100;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment