javascript - การประกาศแอตทริบิวต์ของ Angular 2 ไม่สามารถคอมไพล์ได้
โค้ดต่อไปนี้
import {Attribute, Component, View} from 'angular2/angular2';
@Component({
selector: 'card'
})
@View({
templateUrl: "app/design/card/card.html",
styleUrls: ["app/design/card/card.css"],
directives: []
})
export class Card {
constructor(@Attribute('no-teaser') noTeaser) {
this.active=false
}
}
ให้ข้อผิดพลาดกับฉัน
Unable to resolve signature of parameter decorator when called as an expression. Supplied parameters do not match any signature of call target.
@Attribute('home')
เมื่อแปลง TypeScript เป็น JavaScript
ฉันกำลังใช้ Alpha 37, คำจำกัดความล่าสุดจาก DefinitelyTyped, และฉันกำลังใช้ atom-typescript (ซึ่งใช้เวอร์ชัน typescript ล่าสุด)
คำตอบ #1
ไม่สามารถแก้ไขลายเซ็นของตัวตกแต่งพารามิเตอร์เมื่อถูกเรียกเป็นนิพจน์ พารามิเตอร์ที่ส่งมาไม่ตรงกับลายเซ็นใด ๆ ของเป้าหมายที่เรียก
การค้นหาข้อผิดพลาดนี้ใน Google พบว่า: https://github.com/Microsoft/TypeScript/issues/3661
และในนั้นคุณสามารถเห็นได้ว่า :
การตกแต่งพารามิเตอร์ของฟังก์ชันแบบเป็นทางการในปัจจุบันยังไม่อยู่ในข้อเสนอของ ES7
ดังนั้นฉันสงสัยว่า constructor(@Attribute('no-teaser') noTeaser) ถูก ตั้งใจ ไม่อนุญาตใน TypeScript ล่าสุด (ลองใช้ ntypescript ดูได้ที่ https://github.com/TypeStrong/ntypescript) โปรดรายงานเป็นปัญหาไปยัง Microsoft/TypeScript ถ้าเป็นกรณีนี้
เป็นไปได้ไหมที่จะบอก atom-typescript ว่าจะใช้เวอร์ชันของ tsc ใด?
ไม่ง่ายนัก เพราะเวอร์ชันเก่าของ TSC อาจไม่ เข้ากันได้กับ API ของเวอร์ชันล่าสุด ... แต่มีตัวเลือกนี้: https://github.com/TypeStrong/atom-typescript/blob/master/docs/faq.md#can-i-use-a-custom-typescript-compiler
คำตอบ #2
นี่คือปัญหาเกี่ยวกับวิธีที่นิยาม Attribute annotation ใน Angular ฉันเจอข้อผิดพลาดเดียวกันเมื่อพยายามสร้าง annotation ของตัวเอง:
export function Attribute(name: string) {
return function(a, b) {
console.log(a);
console.log(b);
}
}
ให้ข้อผิดพลาดเหมือนของคุณ ดังนั้นเมื่อฉันเปลี่ยนเป็นอันนี้:
export function Attribute(name: string) {
return function(a, b, c) {
console.log(a);
console.log(b);
console.log(c);
}
}
ข้อผิดพลาดหายไป ดูเหมือนว่าคุณจำเป็นต้องส่งปัญหาไปยังโครงการ Angular
