Is there a way to tell VSCode that an object is of a certain type so that code hinting and code intelligence work? I am using ES2015 I believe.
As an example, let's say I'm populating an array with specific objects:
var person = new Person();
var person2 = new Person();
var person3 = new Person();
var people = [person, person2, person3];
// later on - see second example
var person = people[0];
I don't think that VSCode knows what type of object this is.
I know I can use JSDoc hinting something like so:
/* {Person} */
var person = people[0];
But this looks out of place and unformatted when reading it back later.
Is there a way to tell VSCode the type of object any other way?
I have figured out one way but I don't like it:
var person = new Person();
person = people[0];
Update:
I'm actually defining the value on an HTML Option element and retrieving it later in the List change handler:
function createList() {
// loop through items and add them as option
{
var optionName = useListItem ? "li" : "option";
var option = document.createElement(optionName);
option.name = people[i].name;
option.value = people[i]; // in the browser this is converted to a primitive but it remains an object in the environment i'm in
myList.appendChild(option);
}
}
function listChangeHandler() {
var person = myList.value; // vscode does not know what this is
}