我有一個具有兩個重載方法的 Android-Java 類package com.test;public class A{ public void theMethod(Bitmap bitmap){ ... } public void theMethod(int resource){ ... }}我正在嘗試在Nativescript-Angular程序中擴展該類:class ExtendedA extends com.test.A{ public theMethod(bitmap : android.graphics.Bitmap) : void{ ... }}但我有這個錯誤Property 'theMethod' in type 'ExtendedA' is not assignable to the same property in base type ‘A’. Type ‘(bitmap : Bitmap) => void' is not assignable to type '{ (param: Bitmap): void; (param : number): void; }'. Types of parameters 'bitmap' and 'param' are incompatible. Type 'number' is not assignable to type 'Bitmap'.PD 我沒有 com.test.A 類的代碼。
1 回答

冉冉說
TA貢獻1877條經驗 獲得超1個贊
在您的 tsconfig.json 文件中,您需要制作--strictFunctionTypes:true。
"compilerOptions": {
"module": "commonjs",
"strictFunctionTypes": true,
"downlevelIteration": true
}
PS,如果您的參數計數在 A 類中不同,則 Java 方法重載由開發人員通過顯式檢查調用函數的參數計數來處理。
添加回答
舉報
0/150
提交
取消