fable-compiler / ts2fable

Parser of Typescript declaration files
http://fable.io/ts2fable/
Apache License 2.0
223 stars 34 forks source link

What's the deal with typeof? #300

Open cmeeren opened 5 years ago

cmeeren commented 5 years ago

I'm working on bindings for Electron. A major high-level type is this (TS):

interface MainInterface extends CommonInterface {
  app: App;
  autoUpdater: AutoUpdater;
  BrowserView: typeof BrowserView;
  BrowserWindow: typeof BrowserWindow;
  ClientRequest: typeof ClientRequest;
  contentTracing: ContentTracing;
  Cookies: typeof Cookies;
  Debugger: typeof Debugger;
  dialog: Dialog;
  DownloadItem: typeof DownloadItem;
  globalShortcut: GlobalShortcut;
  inAppPurchase: InAppPurchase;
  IncomingMessage: typeof IncomingMessage;
  ipcMain: IpcMain;
  Menu: typeof Menu;
  MenuItem: typeof MenuItem;
  net: Net;
  netLog: NetLog;
  Notification: typeof Notification;
  powerMonitor: PowerMonitor;
  powerSaveBlocker: PowerSaveBlocker;
  protocol: Protocol;
  session: typeof Session;
  systemPreferences: SystemPreferences;
  TouchBar: typeof TouchBar;
  Tray: typeof Tray;
  webContents: typeof WebContents;
  WebRequest: typeof WebRequest;
}

Notice all the typeof. In F#, this is converted to obj:

type [<AllowNullLiteral>] MainInterface =
    inherit CommonInterface
    abstract app: App with get, set
    abstract autoUpdater: AutoUpdater with get, set
    abstract BrowserView: obj with get, set
    abstract BrowserWindow: obj with get, set
    abstract ClientRequest: obj with get, set
    abstract contentTracing: ContentTracing with get, set
    abstract Cookies: obj with get, set
    abstract Debugger: obj with get, set
    abstract dialog: Dialog with get, set
    abstract DownloadItem: obj with get, set
    abstract globalShortcut: GlobalShortcut with get, set
    abstract inAppPurchase: InAppPurchase with get, set
    abstract IncomingMessage: obj with get, set
    abstract ipcMain: IpcMain with get, set
    abstract Menu: obj with get, set
    abstract MenuItem: obj with get, set
    abstract net: Net with get, set
    abstract netLog: NetLog with get, set
    abstract Notification: obj with get, set
    abstract powerMonitor: PowerMonitor with get, set
    abstract powerSaveBlocker: PowerSaveBlocker with get, set
    abstract protocol: Protocol with get, set
    abstract session: obj with get, set
    abstract systemPreferences: SystemPreferences with get, set
    abstract TouchBar: obj with get, set
    abstract Tray: obj with get, set
    abstract webContents: obj with get, set
    abstract WebRequest: obj with get, set

What's up with all the typeof members in the TS definition? Do those make sense to include in the binding, and why are they obj in F#? Doesn't typeof in TS just return the string name of a type?

cmeeren commented 5 years ago

Based on this SO answer, I guess all the obj stuff should actually be the corresponding -Static types.