W jaki sposób byłaby typu adnotacje?

głosy
1

Załóżmy, że jestem definiowania moduł, a mam pewne definicje funkcji takich jak to:

export function bodyParser(options?:any): 
  (req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
export function errorHandler(opts?:any): 
  (req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
export function methodOverride(): 
  (req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
export function favicon(url: string, opts? ): 
  (req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
export function logger(type: string, opts? ): 
  (req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;

Ja wielokrotnie używając tego typu powrotu adnotacji:

(req: ExpressServerRequest, res: ExpressServerResponse, next) =>void

Czy istnieje sposób określić tego typu, należy przypisać mu nazwę, a po prostu odwołać się do nazwy zamiast powtarzać to samo?

Utwórz 04/10/2012 o 23:51
źródło użytkownik
W innych językach...                            


1 odpowiedzi

głosy
6

Tak! Można użyć interfejsu z podpisem połączenia:

interface MyCallSignature {
    (req: ExpressServerRequest, res: ExpressServerResponse, next): void;
}

Teraz można go używać jak:

export function bodyParser(options?: any): MyCallSignature
Odpowiedział 04/10/2012 o 23:56
źródło użytkownik

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more