Created
November 9, 2018 01:47
-
-
Save zcherries/a82e057992b270d164405fc85f5ee661 to your computer and use it in GitHub Desktop.
examples of typescript annotations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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