[SOLVED] Enabling TypeScript support by using PlayCanvas TS Template Project

I’m following the steps in the: GitHub - playcanvas/playcanvas-editor-ts-template: A simple TypeScript template for PlayCanvas that can also sync with your playcanvas.com project template project. I’m using MacOS and VSCode for the text editor. When I complete all the steps, I get this error in the scripts:

When I delete const pc : typeof _pc; line from the global.d.ts file, all error goes away. Should I delete it or would it cause any side effects?

up

up

The types file in the template project is so that you can have auto complete in VSC

Since you have playcanvas.d.ts file somewhere as well (given the error message in the first post), you can delete the global.d.ts file and it would be fine

2 Likes

Thank you for your help. Now I understand the problem. I’m wondering why it is included in the template project in the first place.

I’m not sure where the playcanvas.d.ts file has come from in your project. When the template was originally created, types weren’t available so it was manually added to the template

It’s been imported to the project via node_modules. Playcanvas npm package contains types so when I run npm install in the template project, it downloads playcanvas.d.ts file too.

Hm, interesting. I wonder if VSC has changed since this template was made and it automatically picks up the types in the node modules now. Or now PlayCanvas NPM ships with the d.ts by default?

1 Like

Please pull the latest template from GitHub. I just submitted this PR which fixes everything correctly:

I also updated NPM dependencies to latest so you’ll need to npm i.

1 Like

Thank you for the quick fix. I’ll try it ASAP.

1 Like