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

Typings for read-write variables #49

Open
daniel-stoneuk opened this issue Apr 19, 2022 · 1 comment
Open

Typings for read-write variables #49

daniel-stoneuk opened this issue Apr 19, 2022 · 1 comment

Comments

@daniel-stoneuk
Copy link

Please forgive me if some of my terminology is incorrect, I'm fairly new to JXA and I haven't been able to find much documentation on it.

I'm using this project in a TypeScript application and it's working great - thank you for such a cool idea and execution.

I've run into an issue with setting read-write variables. The current typings are fine for retrieving an attribute such as .index()

const windowIndex = safariWindow.index()

But there doesn't seem like there is a way to set the attribute without TS complaining. The two ways of setting that I am aware of are

safariWindow.index = 0
safariWindow.index.set(0)

I have had a think and I don't believe we can make a TS type to satisfy both the function call getter and the direct assignment setter, so I propose new interfaces that can be added to the .d.ts files for ReadOnly and ReadWrite attributes.

e.g.

  export interface ReadWrite<T> {
    (): T;
    set: (value: T) => void;
  }

...

    index: ReadWrite<number>;

If this would be a useful and acceptable change for you, I'd be happy to do the work and make a PR.

@jakiestfu
Copy link

+1 to this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants