2017-07-31 25 views
0

我很新,但嘗試學習。我正在使用打字稿處理原生項目。特別是創建權限文件使用鏈接this如何打印使用接口方法創建其他打字稿文件的文件?

我基本上是一個攝像頭和存儲方法和一些關於如何在我的項目

const Permission = require('react-native-permissions') 
import React from 'react' 
import { 
StyleSheet, 
TouchableHighlight, 
Text, 
View, 
Alert, 
AppState, 
Platform, 
} from 'react-native' 

interface Props extends { 
string: [] 
} 

interface PermissionsState extends { 
status: {}, 
} 

class Permissions extends React.Component<Props,PermissionsState> { 
constructor(props) { 
Permission.check([type]) 
type PermissionStatus = 'granted' | 'denied' |'never_ask_again'; 



this.state = { 

}; 
} 

render() { 
return (
render() { 
return (
<View> 
<View/> 
) 
    } 
} 





export default new Permissions() 

創建接口模塊和我的錯誤開始interface Props extends {線和錯誤混亂描述是:

接口只能使用可選的類型參數來擴展標識符/限定名稱。 (屬性)字符串:undefined []

回答

0

您所要做的就是從兩個界面的聲明中刪除extends關鍵字。因爲它們實際上並沒有擴展任何東西並且自己做出反應並不需要它們實現/擴展任何其他接口/類。

所以,你的代碼可以是這個樣子:

const Permission = require('react-native-permissions'); 
import React from 'react'; 
import { 
     StyleSheet, 
     TouchableHighlight, 
     Text, 
     View, 
     Alert, 
     AppState, 
     Platform, 
    } from 'react-native'; 

interface Props 
{ 
    names: string[]; 
} 

type PermissionStatus = 'granted' | 'denied' |'never_ask_again'; 

class PermissionsState 
{ 
    public status: PermissionStatus; 
} 

export class Permissions extends React.Component<Props, PermissionsState> 
{ 
    constructor(props: Props, context: any) 
    { 
     super(props, context); 

     this.state = new PermissionsState(); 
    } 

    public render() 
    { 
     return(<View/>); 
    } 
} 
+0

一些錯誤大約開始這條線;導出類權限....錯誤的名稱是:類'權限'錯誤地擴展基類'組件'。 屬性'呈現'的類型不兼容。 類型'()=>布爾型'不可分配爲鍵入'()=> false |元件'。 類型'布爾值'不可分配爲鍵入'false |元件'。 –

+0

確保你用'tsx'擴展名來聲明你的代碼。不'ts'。 – Amid

+0

我有其他文件在ts格式,哪個文件是我使用的接口模塊,它的工作流暢。 –