Excel with TypeScript

You can convert your JavaScript project to use TypeScript.


Rename Home.js

Rename Home.js to Home.ts


Create Office.d.ts

Create a new typescript file called 'Office.d.ts' at the root of the web project.
(Right click the web project, Add > New Item)
Scroll down and choose TypeScript File
Enter the name 'Office.d.ts'
Press Add
Open a browser and display the type definitions file for Office.js
https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/office-js/index.d.ts
Copy the contents and paste it into the Office.d.ts file


Create jQuery.d.ts

Create a new typescript file called 'jQuery.d.ts' at the root of the web project.
(Right click the web project, Add > New Item)
Scroll down and choose TypeScript File
Enter the name 'jQuery.d.ts'
Press Add
Open a browser and display the type definitions file for Office.js
https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/jquery/misc.d.ts
Copy the contents and paste it into the jQuery.d.ts file


Create tsconfig.json

Create a new JSON file called 'tsconfig.json' at the root of the web project.
(Right click the web project, Add > New Item)
Scroll down and choose JSON file.
Enter the name 'jQuery.d.ts'
Press Add
Open the file and add the following:

{ 
   "compilerOptions" : {
      "skipLibCheck" : true
      "lib" : ["es5", "dom", "es2015.promise"]
   }
}

Edit Home.ts

Open the 'Home.ts' file and add the following declaration at the top

declare var fabric : any; 

Remove the single quote marks from '1.1'.
Find the 'displaySelectedCells' function and add an additional null parameter
above the 'function (result) {


Start Debugging

Press F5



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext