I am using JS for my development. Is there any way to have intellisense (auto-suggest the method names / members) if I have an object that takes in another object in its constructor?
Example:
// sampleobj.js
import Consumer from './consumer.js'
class Sample {
print () {
console.log('hello this is inside sample')
}
}
const sample = new Sample()
const consumer = new Consumer(sample)
consumer.consumerPrinter()
As you can see above, intellisense works fine, it suggests the Consumer object's methods.
My problem is the other way around. Since Consumer takes in Sample object in its constructor, how can I make VS Code suggest Sample's methods inside Consumer class?
class Consumer {
constructor(sample) {
this.sample = sample
}
consumerPrinter () {
console.log('this prints inside consumer')
}
accessSampleMethod () {
// this.sample. -- how to have intellisense here to suggest Sample's methods?
}
}
export default Consumer
As you can see on line 11, this.sample doesn't have any autosuggestions - how to have intellisense here?
Or is there an easy way to let the Consumer class know that sample argument in the constructor is of type Sample class?