0

I want to know what is meaning of this is:

export type VSelect = VTextField & {
   reset: () => void;
   clearableCallback: () => void; 
}

so I want to know meaning of this type specially reset: () => void

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • @Gabriel Heming what is benifet of use this type with reset: () => void; I tried to understand the usage of it – mohammad rida Nov 23 '22 at 09:39
  • The benefit is the [strong typed](https://stackoverflow.com/questions/2351190/static-dynamic-vs-strong-weak) definition. The usage is that you are defining the parameter `reset` as a `function` that has no parameters and returns `void`. So, when using it, you have to pass a function on `reset` and `clearableCallback` parameters. – Gabriel Heming Nov 23 '22 at 09:45

1 Answers1

1

A type is declared this way:

export type TypeName = {
   property1: type,
   property1: type,
   property1: type,
   /** ... */
}

So here, () => void is the type of a function that doesn't have any parameter, and is returning void.

So you can suppose that the reset function is like that:

const reset = function (): void {
   /** some code */
}

Hence, you can do the same way with whatever you like, eg:

const getUserById = function async (userId: string): Promise<User | null> {
   /** some code */
}

export type UserService = {
  getUserById: (userId: string) => Promise<User | null>
}
Kharente Deuh
  • 206
  • 2
  • 6