SplitmediaLabsLimited / xjs

XSplit JS Framework. Make plugins for XSplit Broadcaster, quickly and easily.
Other
39 stars 11 forks source link

Typescript type definitions #315

Open ghost opened 4 years ago

ghost commented 4 years ago

Hi, I am looking for typescript typings (.d.ts) for xjs.js.

Even though the lib is written in ts the project does not emit .d.ts typings, and I cannot use the .ts files as is because they are written for typescript 1.6

I am posting my temporary solution here so that other people can do the same and to show my interest in official typescript support.

  1. download this repository
  2. copy src, defs and modules into a new project
  3. install a recent typescript yarn add typescript
  4. add this tsconfig.json
    {
    "compilerOptions": {
        "declaration": true,
        "declarationDir": "types",
        "emitDeclarationOnly": true
    }
    }
  5. compile with yarn tsc
  6. copy everything from types/src to a new folder called xjs, this will be our drop-in package
  7. in every .d.ts file, remove the /// reference lines at the top (typescript knows those types from lib es2015)
  8. add xjs.js and the following package.json
    {
    "main": "xjs.js",
    "types": "index.d.ts"
    }
  9. in your plugin project, add this new xjs folder to your src path
    src/
    |- xjs/
    |- core/
    |- internal/
    |- system/
    |- util/
    |- window/
    |- index.d.ts
    |- package.json
    |- xjs.js
    |- index.ts
  10. use like
    
    import xjs from './xjs';

xjs.ready({}).then(() => { ... });



This is not a perfect solution and some typings will still throw errors,
that should be easily fixed by correcting the .d.ts
SML-MeSo commented 4 years ago

Thank you for posting your temporary solution as this is definitely helpful for developers using typescript. I'm afraid we can't readily move to higher typescript versions (which should have been way overdue) due to docgen reasons, which will definitely take a considerable amount of work.

That being said, development for version 3.0 is underway. :) This newer version, albeit, a breaking one, is more modern and uses the latest typescript. This should also be cleaner, and definitely more lightweight than the current one, so we're looking forward to its release.