2017-08-10 81 views
0

我想將jsx重寫爲tsx。我有一個重寫的反應,引導方法方法的代碼:基礎構造函數必須都具有相同的返回類型

import {Panel} from 'react-bootstrap'; 
class CustomPanel extends Panel { 
    constructor(props, context) { 
     super(props, context); 
    } 

    handleClickTitle =() => { 
     return; 
    } 
} 

打字稿compilator拋出異常

Base constructors must all have the same return type 

如何解決呢?打字稿版本2.3.4

+0

什麼會解決你的問題(但不會導致它擺在首位)是完全忽略構造函數。只調用'super()'的構造函數是多餘的。 –

+0

如果刪除構造函數我有相同的類型加密錯誤 MyFile.tsx(2,27):錯誤TS2510:基礎構造函數必須都具有相同的返回類型 – Sundved

回答

1

骯髒的黑客的反應,引導產業

const UntypedPanel = Panel as any; 
class CustomPanel extends UntypedPanel { 
    handleClickTitle =() => { 
     return; 
    } 
} 
const TypedCustomPanel = CustomPanel as any as React.ClassicComponentClass<PanelProps>; 
相關問題