How do you add methods when using typescript?
See original GitHub issueI believe I might have found an issue with how cheerio exports types, but I’m new to typescript, so I’m not sure I’m not just missing how to get it done.
I’m running v1.0.0-rc.5, and I’d like to be able to add some methods to the Cheerio
interface, so that when I run a selector query, I get back the full api (both mine and the core methods). I had better luck using @types/cheerio
, as it seemed to expose more of the API, but I wasn’t able to get it fully working there either. For that reason, I’m not sure #1682 is going to fully solve the problem.
I’d like to be able to include a code sample, but working against v1, nothing I came up with is close. If it is possible with the current release, I’d just like to know how to do it. Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Is there a way to add methods on the fly to a class using ...
This works great for adding static methods to js classes but I was looking to add methods to the prototype so they would...
Read more >Functions - TypeScript: Handbook
Functions are the fundamental building block of any application in JavaScript. They're how you build up layers of abstraction, mimicking classes, ...
Read more >How To Use Functions in TypeScript - DigitalOcean
In this section, you will create functions in TypeScript, and then add type information to them. ... In this example, sum is the...
Read more >I want to add methods to Object : r/typescript - Reddit
I want to add methods to Object. Is there a convention for providing additional methods to existing classes (like you can with obj.member ......
Read more >TypeScript Interfaces - TutorialsTeacher
An interface is defined with the keyword interface and it can include properties and method declarations using a function or an arrow function....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, this issue should be re-opened. I don’t know how #1407 got it working. Perhaps he was using
@types/cheerio
? Merging doesn’t work on any level (global, module, namespace). Any attempt just overrides the base interfaces. I can’t be sure, but I suspect the issue is that the interfaces aren’t being exported. In the examples here, they are exporting everything they merge.Just want to add, you need to include
export {}
(or export anything) in your.d.ts
file for the new method to work. Otherwise the custom definition overrides the basic export types.