The intellisense of VSCode doesn’t work when destructuring an object, it returns any
as the type, no matter what.
I tried:
/**
* @returns {{name:String,surname:String}}
*/
function Test(){
return {name:"John",surname:"Doe"};
}
const {name,surname} = Test(); // Intellisense shows "any" for both
I was expecting to get proper type information, in this case, string
.
New contributor
Kebs Studios is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
It helps to create a type definition:
/**
*
* @typedef {Object} NameType
* @prop {'John'} name
* @prop {'Doe'} surname
*/
/**
* @returns {NameType}
*/
function Test() {
return { name: 'John', surname: 'Doe' };
}
const { name, surname } = Test(); // Intellisense shows the proper type for both