Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript type definitions #315

Open
ghost opened this issue Jun 24, 2020 · 1 comment
Open

Typescript type definitions #315

ghost opened this issue Jun 24, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 24, 2020

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
    }
}
  1. compile with yarn tsc
  2. copy everything from types/src to a new folder called xjs, this will be our drop-in package
  3. in every .d.ts file, remove the /// reference lines at the top (typescript knows those types from lib es2015)
  4. add xjs.js and the following package.json
{
    "main": "xjs.js",
    "types": "index.d.ts"
}
  1. 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
  1. 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
Copy link
Collaborator

SML-MeSo commented Jul 23, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant