我正在跟着一個PluralSight課程並練習在Angular2中編寫基本服務。我有以下服務文件:錯誤TS7027:在Angular2中檢測到無法訪問的代碼TypeScript服務類
customer.service.ts
import { Injectable } from '@angular/core';
@Injectable()
export class CustomerService {
constructor() {}
getCustomers() {
return
[
{id: 1, name: 'Ward'},
{id: 2, name: 'Joe'},
{id: 3, name: 'Bill'},
{id: 4, name: 'Bob'},
{id: 5, name: 'Levi'},
{id: 6, name: 'Brian'},
{id: 7, name: 'Susie'}
];
}
}
當我使用npm start
我收到以下錯誤啓動的精簡版服務器:
[email protected] start C:\Dev\my-proj
tsc && concurrently "tsc -w" "lite-server"
app/customer/customer.service.ts(10,3): error TS7027: Unreachable code detected.
當我註釋掉了返回塊,lite-server啓動正常,所以它似乎是它不喜歡的回報。任何幫助,將不勝感激。
getCustomers真的被調用嗎? – jonrsharpe
http://stackoverflow.com/questions/8528557/why-doesnt-a-javascript-return-statement-work-when-the-return-value-is-on-a-new 嘗試移動您的返回的數組與return語句相同的行 – LLai