Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new TypeScript definition setting #20

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

FraserConnolly
Copy link

I have added a new setting to allow users to specify their own TypeScript definition files that will be prefixed to source files.

This has been extremely useful in my work as we have a large number of PlayCanvas scripts that call each other and I found myself having to continually refer to other files to ensure that I was typing out field and functions names correctly. So, I created a .d.ts file that declares TypeScript classes for the script files that I commonly use.

For example this is how I would declare a script that has a single attribute 'textEntity' that is an entity:

declare class {ScriptName} extends pc.ScriptType {
textEntity: pc.Entity;
}

Now when using Visual Studio Code I can use intellisense to reduce the change of an error when I'm working with that script.

…finition files the be prefixed to source files.
@@ -15,9 +15,23 @@ class CloudStorageProvider {

this.context = context;
this._onDidChangeFile = new vscode.EventEmitter();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

const config = vscode.workspace.getConfiguration('playcanvas');

if (config.get('usePlaycanvasTypes')){
this.playCanvasTypesReference = '///<reference path="' + filePath + '" />;\n';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.playCanvasTypesReference = '///<reference path="' + filePath + '" />;\n';
this.playCanvasTypesReference = `///<reference path="${filePath}" />;\n`;

let typeScriptDefinitionFilePaths = config.get('additionalTypeScriptDefinitionFiles');
if ( typeScriptDefinitionFilePaths ){
for (let index = 0; index < typeScriptDefinitionFilePaths.length; index++) {
this.additionalTypesReferences += '///<reference path="' + typeScriptDefinitionFilePaths[index] + '" />;\n';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.additionalTypesReferences += '///<reference path="' + typeScriptDefinitionFilePaths[index] + '" />;\n';
this.additionalTypesReferences += `///<reference path="${typeScriptDefinitionFilePaths[index]}" />;\n`;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants