Skip to content

Commit

Permalink
feat(types): support Application<T>(name) (#6)
Browse files Browse the repository at this point in the history
```ts
import { Application } from "../src/index";
import { GoogleChrome } from "./fixtures/GoogleChrome";
// Pass Custom Application type as generics
const chrome = Application<GoogleChrome>("Google Chrome");
const frontWindow: GoogleChrome.Window = chrome.app.windows[0];
```
  • Loading branch information
azu authored Sep 5, 2018
1 parent 4aa1185 commit fb0d4f9
Show file tree
Hide file tree
Showing 6 changed files with 555 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/@jxa/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"scripts": {
"build": "cross-env NODE_ENV=production tsc -p .",
"prepublish": "npm run --if-present build",
"test": "npm run build",
"test": "tsc -p test",
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
"watch": "tsc -p . --watch",
"dts:update": "node tools/sdef-to-dts.js"
Expand Down
7 changes: 7 additions & 0 deletions packages/@jxa/types/src/Application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Reminders } from "./core/Reminders";
import { Safari } from "./core/Safari";
import { DVDPlayer } from "./core/DVDPlayer";
import { iTunes } from "./core/iTunes";

export = Application;
export as namespace Application;

Expand All @@ -32,6 +33,11 @@ type App = typeof Application & Application._StandardAdditions & Application.Any
* bundle ID or name or path or remote machine
*/
declare function Application(name: string): typeof Application & Application._StandardAdditions & Application.AnyValue;
/**
* 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;
declare function Application(name: "Calendar"): App & Application._Calendar;
declare function Application(name: "Contacts"): App & Application._Contacts;
declare function Application(name: "Database Events"): App & Application._DatabaseEvents;
Expand Down Expand Up @@ -60,6 +66,7 @@ declare function Application(name: "VoiceOver"): App & Application._VoiceOver;
* process ID
*/
declare function Application(id: number): typeof Application & Application._StandardAdditions & Application.AnyValue;
declare function Application<T>(id: number): typeof Application & Application._StandardAdditions & Application.AnyValue & T;

declare namespace Application {
// FIXME: very hack to avoid the Error
Expand Down
Loading

0 comments on commit fb0d4f9

Please sign in to comment.