Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

date restrictions to be added to main method

$
0
0

I have a method in my react-native-library that takes "from" and "to" Date as input.
I want to add a restriction in the below code.
"to" Date should always be greater than "from" Date.
How and where can i add this restriction??

const getData: getDataMethod = async (                //main method  identifier,  options) => {  const option = prepareInput(options)  return option}const prepareInput = (options: InputOptions) => {        //prepareInput function  const limit = options.limit ?? 0  const ascending = options.ascending ?? true  const from = dateToString(options.from)  const to = dateToString(options.to)  return { limit, ascending, from, to }}const dateToString = (date?: Date | null): string => {       //date to String function  return date ? date.toISOString() : new Date(0).toISOString()}export type InputOptions = {      //type declaration  from?: Date  to?: Date  limit?: Number  ascending?: boolean};

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>