klesun / deep-js-completion

A Webstorm/IDEA plugin for js object property completion inferred from a complex context
MIT License
11 stars 0 forks source link

The jsdoc format of referencing a var as a type supported by the plugin #10

Closed klesun closed 5 years ago

klesun commented 5 years ago

Even though native jsdoc format is pretty useful itself compared to some other languages, it still lacks one vital feature - an ability to specify type that references some other var in your code. The plugin adds that feature with the = format, like this:

let makeBilling = () => ({
    ccVendor: 'visa',
    ccNumber: '4111111111111111',
    expirationDate: '08/19',
});

/** @param billing = makeBilling() */
let processBilling = (billing) => {
    billing.e;
};

image

You can specify type of function argument with @param or declared variable with either @var or @type. You can also reference any var defined in other file with at('FileName.js').varName:

/** @type params = {
 *     form: at('RbsClient.js').formParams,
 *     protocol: 'IQ JSON RPC',
 * } */
let params = await readPost();

image

You can type any valid javascript expression after the = (for example await to get type of T from Promise<T>):

/**
 * @var person = {
 *     name: 'Vasya Pupkin',
 *     contacts: await at('RbsClient.js').whenContacts,
 * }
 */
let person = getCachedPerson();

image

giladbarnea commented 5 years ago

Thank you, this feature is really useful.