Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Using TypeScript in React Native Projects
To demonstrate TypeScript usage, Mobile SDK provides a new template app. You can view or download the new template at the ReactNativeTypeScriptTemplate directory of the SalesforceMobileSDK-Templates GitHub repo.
- Imports are the same.
- Code changes for new types are minimal.
1interface Response {
2 records: Record[]
3}
4
5interface Record {
6 Id: String,
7 Name: String
8}
9
10interface Props {
11}
12
13interface State {
14 data : Record[]
15}The Record type is used internally in the Response interface. The new template applies the other three types to parameters of the original script. For example, Props and State apply to the constructor:
1class ContactListScreen extends React.Component<Props, State> {
2 constructor(props:Props) {
3 super(props);
4 this.state = {data: []};
5 }1(response:Response) => that.setState({data: response.records}),
2 (error) => console.log('Failed to query:' + error)