Comments (9)
const emacs = <EmacsType> Application('Emacs')
?
from jxa.
@LoganDark your proposal gives me the following error:
[ts]
Type 'typeof Application & _StandardAdditions & AnyValue' cannot be converted to type 'Emacs'.
Property 'close' is missing in type 'typeof Application & _StandardAdditions & AnyValue'.
(alias) Application(name: string): typeof Application & Application._StandardAdditions & Application.AnyValue (+25 overloads)
export namespace Application
from jxa.
Does your type extends App
?
Where App
is:
from jxa.
Ah, thanks @LoganDark
I got the following snippet to work:
import "@jxa/global-type";
import {Emacs} from "./types/Emacs";
import Application from "@jxa/types/src/Application";
type App = typeof Application & Application._StandardAdditions & Application.AnyValue;
const emacs = <App & Emacs> Application("Emacs");
Where types/Emacs
is the .d.ts
made by @jxa/sdef-to-dts
.
@azu: Feel free to close this issue or advice me on how this could fit into this library.
from jxa.
Maybe, we can provide more generics way.
import "@jxa/global-type";
import {Emacs} from "./types/Emacs";
// Maybe, types export `Application`
import { Application } from "@jxa/types";
// TODO: `Application` support Custom Application by generics.
const emacs = Application<Emacs>("Emacs");
// Emacs is `Application & Application._StandardAdditions & Application.AnyValue & Emacas`;
Implemention:
/**
* Pass custom Application type as generics
* Return Application's StandardAdditions & T type
*/
declare function Application<T>(name: string): typeof Application & Application._StandardAdditions & Application.AnyValue & T;
from jxa.
I've submit PR #6
from jxa.
@havardh I've published 1.2.0
Please try to use this :)
https://github.com/JXA-userland/JXA/releases/tag/v1.2.0
import { Application } from "@jxa/types";
import {Emacs} from "./types/Emacs";
const emacs = Application<Emacs>("Emacs");
from jxa.
@azu Great, I've tested this on 1.2.1 and it works for my use case.
This brings me to the next part of my questions, can we make it more ergonomic to add these types? E.g. an additional repo with these custom types, or a simple npx @jxa/sdef-to-dts Emacs.app
=> Emacs.t.ds
.
from jxa.
@havardh Interesting.
If we get sdef file from app name, we can implement this feature.
(I don't know if that's is possible or impossible.)
Please create another issue.
from jxa.
Related Issues (19)
- sdef-to-dts is missing children elements HOT 1
- tsc v3.3.33 errors on dts @jxa/global-type HOT 2
- @jxa/run: update default max buffer to 100MB HOT 2
- Example passing args to run() HOT 1
- Application() breaks if `esModuleInterop` is `true`
- Need Instructions for Installing in Visual Studio Code HOT 1
- Automator integration
- Readme.md — typo: "JSX" should be "JXA"
- Questions about @jxa/sdef-to-dts HOT 1
- npm Audit Issues with @jxa/sdef-to-dts
- Need Install Instructions for Visual Studio Code (VSC) HOT 2
- How Do I Use System Events.sdef?
- $.NSWorkspace.sharedWorkspace.iconForFile() not work
- Typings for read-write variables HOT 1
- app.systemInfo().IPv4Address is undifine, should be app.systemInfo().ipv4Address
- Array.includes doesn't work anymore HOT 1
- npx command for converting Script Definitions to Type Definitions
- Put types into DefinitelyTyped HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jxa.