:typescript derleme tarih türü hatası
var dateFrom:Date;
var dateTo:Date;
if(typeof discount.dateFrom === "string"){
dateFrom = new Date(discount.dateFrom); // Line 362
} else {
dateFrom = discount.dateFrom;
}
if(typeof discount.dateTo === "string"){
dateTo = new Date(<string>discount.dateTo); // Line 368
} else {
dateTo = discount.dateTo;
}
transpiler döndürür aşağıdaki:
[FULL_PATH]/Quotation.ts(362,37): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'string'.
[FULL_PATH]/Quotation.ts(368,35): error TS2352: Neither type 'Date' nor type 'string' is assignable to the other.
hattı 362 den farkı ve 368, sorunu düzeltmeye çalıştığım iki durum.
Bu gimmiği koddaki başka bir yerde kullandım ve iyi çalıştı. Ben referans için lib.d.ts gelen tarihi yapıcı tanımını içeren ediyorum
: date
den string
bilinen çevirici @danludwig için
new(): Date;
new (value: number): Date;
new (value: string): Date;
new (year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date;
(): string;
# 362 numaralı satırdaki hata açıkça görünüyor ... kurucu argümanı bir "dize" veya bir "sayı" bekliyor, ancak başka bir "Tarih" geçiyorsunuz. 'Discount.dateFrom', üstte bildirilen değişkenle aynı değilse? – danludwig
@danludwig Sanırım hat 368 sorunu düzeltmek gerekiyordu –
Hat # 368 ile ilgili problem, 'Date' den' string''ye bilinen bir dönüşüm olmamasıdır. Bu, geçersiz bir yayın olduğunu söyleyen yazılara benziyor. 'Discount.dateFrom' veya 'discount.dateTo' dize' olması için çalışma zamanı türünün mümkün olması durumunda, bunları 'Tarih' yerine "herhangi bir" olarak bildirmeniz gerekir. – danludwig