Nasıl tipi ek açıklamaları planı ayrı mı?

oy
1

ı bir modül tanımlama ediyorum varsayalım ve bu gibi bazı işlev tanımları vardır:

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;

Ben defalarca bu dönüş tipi notunu kullanıyorum:

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

O türünü tanımlamak için bir yol var mı, ona bir ad atamak ve sadece aynı şeyi tekrar adı yerine başvurmak?

Oluştur 04/10/2012 saat 23:51
kaynak kullanıcı
Diğer dillerde...                            


1 cevaplar

oy
6

Evet! Bir çağrı imzayla bir arayüz kullanabilirsiniz:

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

Şimdi bunu gibi kullanabilirsiniz:

export function bodyParser(options?: any): MyCallSignature
Cevap 04/10/2012 saat 23:56
kaynak kullanıcı

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