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

Adding JSDoc for improved type checking #5

Open
kungfooman opened this issue Nov 24, 2020 · 1 comment
Open

Adding JSDoc for improved type checking #5

kungfooman opened this issue Nov 24, 2020 · 1 comment
Labels
good first issue Good for newcomers

Comments

@kungfooman
Copy link
Collaborator

Simple example from PlayCanvas:

/**
 * @class
 * @name pc.Vec3
 * @classdesc A 3-dimensional vector.
 * @description Creates a new Vec3 object.
 * @param {number|number[]} [x] - The x value. If x is an array of length 3, the array will be used to populate all components.
 * @param {number} [y] - The y value.
 * @param {number} [z] - The z value.
 * @example
 * var v = new pc.Vec3(1, 2, 3);
 */
function Vec3(x, y, z) {
    if (x && x.length === 3) {
        this.x = x[0];
        this.y = x[1];
        this.z = x[2];
    } else {
        this.x = x || 0;
        this.y = y || 0;
        this.z = z || 0;
    }
}

This allows TypeScript/VSCode to deduce all types for near-perfect type checking/autocompletion

@riicchhaarrd riicchhaarrd added the good first issue Good for newcomers label Nov 24, 2020
@kungfooman
Copy link
Collaborator Author

Fixed in 9350930

Everything is fully type checked now:

image

JSDoc can be improved upon, like adding @example, @classdesc or @description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants