Hello,
Now a days, typescript is more preferred to write client-side code. However, it needs to later convert into JavaScript to use in browser. Let's see, how-
- Create New Project >> "Empty Project (.Net Framework)"
- Go to Tools >> NuGet Package Manager >> Manage NuGet Packages for Solution >> Browse >> Node.js
- Install Node.js
- Copy Solution Path
- Open Command Prompt
- CD <Solution Path>
- Then Run "npm install --save @types/xrm"
- It will add node_modules in project
- Add "JavaScript JSON Configuration File". Rename it "tsconfig.json"
- Update tsconfig.json as below
- The highlighted folder must be created in your solution
{ "compileOnSave": true, "complierOptions": { "outDir": "scripts/js", "rootDir": "./scripts/ts", "alwaysStrict": false, "removeComments": false, "noImplicitAny": false, "noEmitOnError": true, "sourceMap": true, "target": "ES2021", "lib": [ "dom", "ES2021" ], "typeRoots": [ "node_modules/@types" ] }, "include": [ "./scripts/ts/**/*" ], "exclude": [ "node_modules", "node_modules/*", "**/*.specs.ts", "**/helper.js" ] }
- Update package.json
- Author Name, Project Name/Description, File Names, Folder Names must be updated as per actual
{ "author": { "name": "Test Author" }, "name": "Demo Project", "description": "Demo Project", "version": "1.0.0", "devDependencies": { "@types/node": "20.5.2", "types/xrm": "^9.0.80", "copyfiles": "^2.2.0", "del-cli": "^3.0.1", "typescript": "5.1.0-dev.20230423", "typings": "^2.1.1" }, "scripts": { "build": "tsc -p tsconfig.json --build", "clean:all": "del-cli Scripts/TS/*.js && del-cli Scripts/TS/*.js.map", "copyfiles": "copyfiles Scripts/**/*.html Scripts/**/*.js Scripts/**/*.css dist" } }
Check package-lock.json
- Update name if required
- It's done. Now test.
- Add new "TypeScript File" in TS folder. Rename it "firstfile.ts"
- Add below code:
namespace Helper { export class Common { public static returnFullName(firstName: string, lastName: string): string { return firstName + " " + lastName; } } }
Save the file. Typescript compiler will compile the file and create 2 files in JS folder
firstfile.js
firstfile.js.map