Giter Site home page Giter Site logo

Comments (9)

LoganDark avatar LoganDark commented on May 24, 2024
const emacs = <EmacsType> Application('Emacs')

?

from jxa.

havardh avatar havardh commented on May 24, 2024

@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.

LoganDark avatar LoganDark commented on May 24, 2024

Does your type extends App?

Where App is:

type App = typeof Application & Application._StandardAdditions & Application.AnyValue;

from jxa.

havardh avatar havardh commented on May 24, 2024

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.

azu avatar azu commented on May 24, 2024

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.

azu avatar azu commented on May 24, 2024

I've submit PR #6

from jxa.

azu avatar azu commented on May 24, 2024

@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.

havardh avatar havardh commented on May 24, 2024

@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.

azu avatar azu commented on May 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.