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

Material#clone: return polymorphic this type #4016

Merged
merged 1 commit into from
Feb 25, 2022

Conversation

kungfooman
Copy link
Collaborator

Fixes one issue in #3995

Before you had to write:

const a = new StandardMaterial;
const b = a.clone() as StandardMaterial;

Now its just:

const a = new StandardMaterial;
const b = a.clone();

And the type is correctly inferred:

image

Because the type system can infer the correct type from this: https://www.typescriptlang.org/docs/handbook/advanced-types.html#polymorphic-this-types

JSDoc doesn't support this as type yet, but I made a PR for that too: playcanvas/playcanvas-jsdoc-template#38

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

Copy link
Contributor

@willeastcott willeastcott left a comment

Choose a reason for hiding this comment

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

Great, thanks! 🙏

@willeastcott willeastcott merged commit 8f3b4e0 into playcanvas:dev Feb 25, 2022
@kungfooman kungfooman deleted the materialCloneThis branch July 19, 2023 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants