I'm currently exploring the usage of TypeScript within a Salesforce project involving RemoteObject
One challenge I'm facing is creating typings for the external JavaScript object syntax.
For example, in JavaScript:
var ct = new RemoteObjectModel.Contact({
FirstName: "Aldo",
LastName: "Michaels",
Phone: "(415) 555-1212"
});
The stumbling block lies in new RemoteObjectModel.Contact()
. How can I define an interface for this?
Below is a snippet of the code I'm attempting to compile:
import React from 'react'
import ReactDOM from 'react-dom'
declare module RemoteObjectModel {
export class Account implements IRemoteObject {
constructor();
get;
set;
}
}
interface IRemoteObject{
get(field: string): any;
set(field: string, value: string): any;
}
interface IAppProps{
remoteObjectModel: RemoteObjectModel
}
export class App extends React.Component<IAppProps, {}>{
public state : IAppState;
constructor(props : IAppProps) {
super(props);
this.state = {
accounts: 0
};
}
public render(){
let account: IRemoteObject = new this.props.remoteObjectModel.Account({
Name : 'hello!',
Active : true
});
console.log(account);
return (
<div>
New Accounts: {this.state.accounts}
Account: {account.get('Name')}
</div>
)
}
}
//set on the global state
declare var remoteObjectModel : IRemoteObjectModel;
ReactDOM.render(<App remoteObjectModel={remoteObjectModel} />, document.getElementById('app'));
However, there's an issue with IAppProps
:
message: 'Cannot find name 'RemoteObjectModel'.'
I'm also uncertain if my question title accurately reflects the problem (please update as needed!)