Define a global context in a function signature, to enforce typing. #43434
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
π Search Terms
β Viability Checklist
β Suggestion
I would like to be able to define that a method can have access to a custom global environment, within the function.
It can be implemented exactly as the this typing.
the main issue is to find a reserved keyword, or syntax to do that.
π Motivating Example
Improve puppeteer extensions.
π» Use Cases
This feature is most useful when we write a code that will be executed in another javascript environment like:
if I use puppeteer-jquery to enable jQuery into my browser.
I can now write:
the jQuery object is available inside the browser but not inside the nodeJS, this code works, but I need to add a dirty
var jQuery: JQueryStatic;
at the top of the filecurrently, the jQuery map method of page signature is:
with a feature to define a custom environment, this code will be replaced by:
and, the jQuery method of page signature will be something like:
proposition:
The
this
parameter named is already reserved and must be placed in a first position.if a
global
parameter is added before thethis
parameter it will be interpreted as a global environment, and so will not need reserving a new reserved keyword.The tsConfig.json can be used to define if the code is used inside a nodeJS or a browser, but when we mixte the two destinations in the same code... it can not be used.
The text was updated successfully, but these errors were encountered: