2017-07-06 20 views
5

Sau khi cập nhật lên nguyên cảo 2.4.1, các dự án biên soạn có sử dụng Actions thể quan sát được từ @ngrx/effects (phiên bản 2.0.3) thấy các lỗi sau ném:Lỗi với Actions thể quan sát được trong @ ngrx/hiệu ứng sử dụng nguyên cảo 2.4.1

Error TS2684: The 'this' context of type 'Actions' is not assignable to method's 'this' of type 'Observable<any>'. 
Error TS7006: Parameter 'action' implicitly has an 'any' type. 
Error TS2345: Argument of type 'Actions' is not assignable to parameter of type 'Observable<Action>'. 
    Types of property 'lift' are incompatible. 
    Type '(operator: Operator<any, Action>) => Observable<Action>' is not assignable to type '<R>(operator: Operator<Action, R>) => Observable<R>'. 
     Types of parameters 'operator' and 'operator' are incompatible. 
     Type 'Operator<Action, R>' is not assignable to type 'Operator<any, Action>'. 
      Type 'R' is not assignable to type 'Action'. 

Làm cách nào để có thể được điều chỉnh lại?

Trả lời

8

nguyên cảo 2.4.1 chặt chẽ hơn thực thi các chữ ký chung của phương pháp lift trong ObservableActions thực hiện quan sát của lift không kiểm tra.

Séc có thể bị tắt bằng cờ dòng lệnh --noStrictGenericChecks hoặc tùy chọn biên dịch noStrictGenericChecks (dưới dạng tham số trong đối tượng "compilerOptions" của tsconfig.json).

Một thay thế cho việc vô hiệu hóa kiểm tra là sử dụng giao diện augmentation nguyên cảo của để xác định một chữ ký chính xác:

import { Action } from "@ngrx/store"; 
import { Observable } from "rxjs/Observable"; 
import { Operator } from "rxjs/Operator"; 

declare module "@ngrx/effects/src/actions" { 
    interface Actions { 
     lift<R>(operator: Operator<Action, R>): Observable<R>; 
    } 
} 

Lưu ý rằng đường dẫn đầy đủ đến các module/file phải được sử dụng; không đủ để chỉ định @ngrx/effects làm tên mô-đun.


Điều này đã được giải quyết với việc phát hành @ngrx/effects2.0.4.

Các vấn đề liên quan