Monday, March 21, 2016

Windows 10 Universal JS + Typescript

While investigating the Windows 10 universal javascript application story, I have been trying to use all the good things that I normally use when developing web applications.  As such, I would like to use TypeScript to help generate valid, working javascript.  Using Typescript is no problem for universal applications as the files are compiled into javascript and available at runtime.

The not-so-obvious part, however, is that by default, no Windows 10 Universal specific definitions are included or available for use by newly created projects.  When working with Web Applications and Windows Universal 10 JS applications, lib.d.ts is available when writing TypeScript files so that things like window.localStorage are available.

When working with universal apps, however, we do not want to use window.localStorage, but instead Windows.Storage.ApplicationData.current.localStorage should be used.  By default, however, this is not available to typescript files.  You must install the definition from nuget or elsewhere.

PM> Install-Package winjs.typescript.definitelytyped
PM> Install-Package winrt.typescript.definitelytyped

These packages will provide definitions for storage and other native APIs that can be called from javascript.

Hopefully this will save someone else hours of searching! :)

No comments:

Post a Comment