This project provides a complete TypeScript development environment for Power Platform web resources, allowing you to write type-safe code with IntelliSense support and automatically sync compiled JavaScript to your web resource folders.
For a step by step guide check out my blog, it contains images with every step required.
https://www.clive-oldridge.com/azure/2025/05/26/power-platform-typescript-development-workflow.html
Power Platform git integration must be exported to the folder src for this to work.
- TypeScript Development: Write type-safe code with full IntelliSense support
- XRM Typings: Complete Dynamics 365/Power Platform API typings included
- Automatic Compilation: Compile TypeScript to JavaScript with proper ES2020 targeting
- Smart Syncing: Automatically sync compiled files to the correct web resource folders
- Easy Setup: Simple commands to create mappings for new web resources
- Git Integration: Seamless integration with Power Platform Git export
βββ typescript/ # Your TypeScript source files
β βββ model-form.ts # Example: Model form logic
β βββ api-example.ts # Example: API integration
βββ dist/ # Compiled JavaScript files
βββ scripts/ # Build and sync scripts
βββ src/webresources/ # Power Platform web resources (Git export)
βββ package.json # Node.js dependencies
βββ tsconfig.json # TypeScript configuration
βββ webresource-mapping.json # Mapping between TS files and web resources
-
Install Dependencies
npm install
-
Create Your First TypeScript Web Resource
npm run new-webresourceThis will:
- Show you all available web resources from Power Platform
- Let you select which one to create a TypeScript file for
- Optionally convert existing JavaScript to TypeScript
- Create the mapping between your TS file and the web resource
-
Compile TypeScript
npm run compile
-
Sync to Web Resources
npm run sync-webresources -
Development Workflow
npm run dev
This compiles and syncs in one command.
| Script | Description |
|---|---|
npm run compile |
Compile TypeScript files to JavaScript |
npm run watch |
Watch TypeScript files and compile on changes |
npm run sync-webresources |
Sync compiled JS to web resource folders |
npm run new-webresource |
Create mapping for a new web resource |
npm run dev |
Compile and sync (development workflow) |
npm run build |
Clean and compile everything |
npm run clean |
Remove compiled files |
-
Create TypeScript mapping:
npm run new-webresource -
Edit your TypeScript file in the
typescript/folder -
Compile and sync:
npm run dev
-
Commit changes:
git add .; git commit -m "Updated web resource"; git push
When you pull new web resources from Power Platform:
-
Pull latest changes:
git pull
-
Create TypeScript mapping for new web resources:
npm run new-webresource -
Start developing in TypeScript with full type safety!
namespace MyWebResource {
export function formOnLoad(executionContext: Xrm.Events.EventContext): void {
const formContext = executionContext.getFormContext();
// Type-safe form operations
const nameAttribute = formContext.getAttribute("name");
if (nameAttribute) {
nameAttribute.addOnChange(attributeOnChange);
}
}
export function attributeOnChange(executionContext: Xrm.Events.EventContext): void {
const attribute = executionContext.getEventSource() as Xrm.Attributes.Attribute;
console.log('Changed:', attribute.getName(), attribute.getValue());
}
}
// Make available globally
(window as any).MyWebResource = MyWebResource;namespace ApiIntegration {
async function fetchData(url: string): Promise<any> {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return await response.json();
} catch (error) {
console.error('API Error:', error);
Xrm.Navigation.openErrorDialog({ message: 'Failed to fetch data' });
return null;
}
}
export function loadExternalData(executionContext: Xrm.Events.EventContext): void {
const formContext = executionContext.getFormContext();
const recordId = formContext.data.entity.getId();
fetchData(`/api/data/${recordId}`).then(data => {
if (data) {
// Update form with fetched data
}
});
}
}The project is configured to:
- Target ES2020 for modern Dataverse development. It provides better language features while still maintaining compatibility.
- Use no module system (for Power Platform compatibility)
- Include XRM typings
- Output to
dist/folder - Preserve comments for debugging
This file maps your TypeScript files to Power Platform web resources:
{
"model-form.ts": "b5a4c6d9-aaec-ef11-be20-000d3ad0347e",
"api-example.ts": "55a4bea9-aaec-ef11-be20-000d3ad0347e"
}- Use Namespaces: Wrap your code in namespaces to avoid global conflicts
- Type Safety: Leverage TypeScript's type system for safer code
- Error Handling: Always handle errors gracefully with try-catch blocks
- Async Operations: Use async/await for better readability
- Form Context: Always check if form context is available before using
- Console Logging: Use console.log for debugging (visible in browser dev tools)
-
"No mapping found" warning:
- Run
npm run new-webresourceto create mapping
- Run
-
Compilation errors:
- Check TypeScript syntax
- Ensure XRM typings are properly imported
-
Sync failures:
- Verify web resource folders exist
- Check file permissions
-
Runtime errors in Power Platform:
- Check browser console for detailed errors
- Ensure compiled JavaScript is ES2020 compatible
Enable watch mode for continuous development:
npm run watchThis will automatically recompile TypeScript files when you save changes.
Feel free to improve this development setup by:
- Adding more example TypeScript files
- Improving the build scripts
- Adding additional tooling
Happy coding with TypeScript and Power Platform! π