After writing a lot of TypeScript: form logic held in multiple files, I thought I would include all my common functions in a helper.ts file. Unfortunately, after importing it into a Form.ts file, I don't seem to get passed an intialisation error as shown below .
Setup
in my TS folder I have run (npm) installed : typscript, @types/node and @types/xrm . My event handler logic works fine if I attach the Form.ts to the form and call any function contained it.
MyProjectRootFolder\front-end\ts\src\code\utils\Helper.ts
// show a simple dialog
export function displayPromptText(titleText : string, promptText : string)
{
let alertStrings = { confirmButtonLabel: "Ok", text:promptText, title:
titleText };
var confirmOptions = { height: 400, width: 450 };
Xrm.Navigation.openAlertDialog(alertStrings, confirmOptions).then(
function (success) {
console.log("Dialog closed using OK button.");
}, function (error) {
console.log(error.message)
}
)
}
MyProjectRootFolder\front-end\ts\src\code\forms\MyForm.ts
import * as helper from "../utils/helper"
// also tried this
// import { displayPromptText } from "../utils/helper";
// if you call the line below say in Form load you get the intialisation error
helper.displayPromptText("test","test");
Both Helper.ts and Form.ts transpile to JavaScript without issues. Whether I import all functions or a single function I don't get passed this error: