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

Add TypeScript type definitions #14

Open
cstoquer opened this issue Apr 20, 2020 · 2 comments
Open

Add TypeScript type definitions #14

cstoquer opened this issue Apr 20, 2020 · 2 comments

Comments

@cstoquer
Copy link
Owner

cstoquer commented Apr 20, 2020

Build is done with Browserify. We can add tsify to compile TypeScript to ES5.

Help and recommendation would be appreciated as my experience with TypeScript is very limited. In particular, we need to answer the following questions:

  • Pixelbox is doing a bit of magic during the build process. I need to do some tests to see how we can approach this problem. How would you structure a TypeScript pixelbox project?
  • How and where should we define type definitions for pixelbox modules? Pixelbox editor can inject @types/pixelbox in node_modules but I'm not sure if it's the best solution.
@TyPhyter
Copy link

@cstoquer It has been a bit since I've worked with browserify, but it does look like tsify will fit the bill. Looks like it supports tsconfig.json or you can pass in settings at build time. As a dev I'd prefer having the tsconfig available, or at least some way to alter the more common settings in the GUI.

In response to your question on itch

In particular, how do you expect a pixelbox project made in TypeScript to look like? Do we need to have the entry point main.js to become main.ts ?

Yeah, I would expect if I toggle the scripting language to TS, I would get a main.ts as my entry point. As for 'where', either just including the declaration files somewhere in the project directory, or publishing them to the @types organization are fine. Because the library itself isn't written in TS, publishing them to @types is considered the "most appropriate", but honestly either is fine. I'm iffy about the idea of injecting them into node_modules rather than just adding @types/pixelbox to devDependencies and installing in the traditional manner, although the former would probably be simpler.

Luckily there are some utilities available for generating TS declaration files from JSDoc'd .js files, though I'm unsure of the quality of the output of such tools. Probably worth looking into.

As for the magic during the build, not sure how it may affect anything discussed so far, happy to take a look if further advice is needed there.

@BlackFenix2
Copy link

@TyPhyter the typescript compiler itself should be enough, I tested out using .ts files and my own tsconfig.json and the compiled output is picked up by pixelbox as long as the output is ES6. i have the .ts files compile a .js file adjacent so its picked up by the pixelbox client.

i could try my hand at a PR, we just really need to transform the src/* files to .js and everything else around can just work as-is.

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

3 participants