Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate src/ExecutionContext #5705

Merged
merged 3 commits into from Apr 22, 2020
Merged

Commits on Apr 22, 2020

  1. chore: migrate src/ExecutionContext to TypeScript

    I spent a while trying to decide on the best course of action for
    typing the `evaluate` function.
    
    Ideally I wanted to use generics so that as a user you could type
    something like:
    
    ```
    handle.evaluate<HTMLElement, number, boolean>((node, x) => true, 5)
    ```
    
    And have TypeScript know the arguments of `node` and `x` based on those
    generics. But I hit two problems with that:
    
    * you have to have n overloads of `evaluate` to cope for as many number
    of arguments as you can be bothered too (e.g. we'd need an overload for
    1 arg, 2 args, 3 args, etc)
    * I decided it's actually confusing because you don't know as a user
    what those generics actually map to.
    
    So in the end I went with one generic which is the return type of the
    function:
    
    ```
    handle.evaluate<boolean>((node, x) => true, 5)
    ```
    
    And `node` and `x` get typed as `any` which means you can tell TS
    yourself:
    
    ```
    handle.evaluate<boolean>((node: HTMLElement, x:  number) => true, 5)
    ```
    
    I'd like to find a way to force that the arguments after the function do
    match the arguments you've given (in the above example, TS would moan if
    I swapped that `5` for `"foo"`), but I tried a few things and to be
    honest the complexity of the types wasn't worth it, I don't think.
    
    I'm very open to tweaking these but I'd rather ship this and tweak going
    forwards rather than spend hours now tweaking. Once we ship these
    typedefs and get feedback from the community I'm sure we can improve
    them.
    jackfranklin committed Apr 22, 2020
    Copy the full SHA
    7b4f31c View commit details
    Browse the repository at this point in the history
  2. whoops

    jackfranklin committed Apr 22, 2020
    Copy the full SHA
    f863119 View commit details
    Browse the repository at this point in the history
  3. linting

    jackfranklin committed Apr 22, 2020
    Copy the full SHA
    fd69197 View commit details
    Browse the repository at this point in the history