-
Notifications
You must be signed in to change notification settings - Fork 102
Merge with Pixi.js #72
Comments
Hey! I would really appreciate guidance on this one from yourself and those of us here. I have almost no exposure to the mechanisms involved with typing's or anything else so I have very little opinion to offer. |
The mechanism is pretty simple in newer versions of TypeScript: basically you add a This could be achieved with a simple PR to Pixi.js. The tricky thing here is that we'd need to add typings for all the plugins into their respective plugins (e.g. pixi-spine, pixi-particles, etc). Would require a little coordinate, but could be ace at resolving versioning issues moving forward. Anyways, I'm pro-TypeScript and would love to see it become a first-class workflow for Pixi.js developers. |
If we are talking about the future of this repo, I vote for tool-generated typings instead of manually managed ones! |
Tool-generated typings (hopefully including comments) is a definite plus, however it should be a separate issue to this one (which it is). Regarding repo-merging, specifically the plugin merges, to my knowledge this would only be possible via Typescript 2.0 (ie; definition augmentation?). If so, the question is should this issue then be put on hold until Typescript 2.0 is out of beta, and, are there any cases (backwards compatibility or otherwise) where users would not update to Typescript 2.0 thereby still requiring access to non-augmented type definitions? |
Don't know if this belongs here or in #70, but the discussion seems to be happening here, so I'm writing it here. I don't think tool generated declaration files are the way to go. (examples are from v.4). TL;DR: JSDoc and TypeScript are not the same. Treat them as such. First example, one-time use interfaces (look at the BitmapText constructor). Second example, the There are two alternatives to this: 2: Actually use mixins. The current JSDoc documents it like the first alternative, and this is also the best way to document it using JSDoc. Third example: TilingSprite.fromImage and TilingSprite.fromFrame (@clark-stevenson should know this one) In this case the problem was solved in a really unclean way, but with a comment stating so, which means a reader of the declaration file shouldn't be confused as to what the actual meaning is. Fourth example, look at There are more examples (like the These could most likely be fixed by some custom annotations in the JSDoc. But this is not my repo, and in the end it is your decision. |
Move Pixi to TypeScript would work.... lol 😛 I am moving at a Glacial pace on this front. Last couple of weeks, I have no build and no errors so progress is pretty much zero. Anyway aside from all of that, I have future concerns. Most of them are highlighted above. Interfaces are not real things, Dependencies can be a problem too. PIXI without EventEmitter sucks. Either dependencies would magically work, they would need to be maintained, or there might actually be 2 styles of JSDoc. (Everyone appears to use a different style/guideline for how to comment code) . I really hate the primitive task of sitting on Github reviewing every PR tho. I was really enticed by #70 |
It is likely going to be the case that these definitions for v4 will be for TypeScript 2.0 only since I see no reason to wait around now that it is final. Need to spend some time wrapping my head around all this but just thought I would share. |
I'm happy to help with this, I just downloaded this repo to start working on v4 definitions, but if you guys have a better plan I'd love to help us get there asap (using Pixi in a project right now) |
The TypeScript 2 release is very interesting, but unfortunately it is not something this repository will necessarily gain from. So now there is a greater need for the DefinitelyTyped version of pixi.js.d.ts` to be updated (any volunteers for that merge?). One solution is to include the declaration file with the main repository by using the Another solution is to delete this repository, and move everything to the DefinitelyTyped project (you can have versioned declarations, like the hammerjs declaration has). The best solution would be to somehow get the |
If you merge an official typescript definitions file into the pixi repo the definitely typed people will mark pixi as deprecated so users get a warning that they don't need it anymore. Also, users would automatically get the typescript definitions working when they updated pixi to the latest, which would produce warnings if they had the old @types installed. Best approach remains merging this into pixi and/or rewriting pixi in typescript. |
We don't need to merge the TypeScript declaration into the pixi repo, some build-script could fetch the latest version from this repository, that way the two repositories could remain separate. |
Makes no sense to do that, what's the advantage over just merging? |
This repository has a couple of branches, one for each major version of PixiJS. Keeping things in separate repositories also helps keeping the two things separate. Everything related to PixiJS and TypeScript is in this repository, while the main repo deals exclusively with JavaScript. |
Moving all further Typescript definitions (keeping old versions here) into the main repo would have other benefits, like being able to easily develop a feature branch with its typings, and anyone that checks out that branch and symlinks it will get the full typings. |
I think the version branches on this repo are misleading, for example you need master for pixi-spine, but v4 for pixijs, even though both are v4. Merging with the main repo is the way forward I think, however I'm still not sure if its possible (even in typescript 2) to augment existing definitions in the case of plugins that extend base classes, for example pixi-display. |
It is possible to augment existing declarations with new ones that extend base classes. declare module PIXI {
interface ShaderConstructor {
new (): PIXI.ShaderInstance;
}
interface ShaderInstance {
baseMethod(): number;
}
export var Shader: ShaderConstructor;
}
// Extended
declare module PIXI {
interface ShaderInstance {
fromExtended(): string;
}
}
var num: number = new PIXI.Shader().baseMethod();
var str: string = new PIXI.Shader().fromExtended(); And you guys convinced me about the merging with main repo thing. I now agree the best thing is to move into the main repo. |
So its basically shelving all classes for interfaces? |
Yes. As I said, it's not pretty. |
😞 Well there goes my plans. Another problem is that V4 was originally a totally different repo, and then V3 became V4 at a unknown point in time. An offshoot of that is not really knowing at what point other libraries (such as Spine) adapted so that is why there is currently 2 branches but v3 is pretty much abandoned. I have no preference at all. To me all that really matters is that there is 1 place where TS dudes go to access Pixi. There seems agreement adding it to the official repo is the way forward and others are way way more qualified than me on the pros and cons of that and the tooling surrounding how to best achieve that end. So long as I can make a weekly PR or so (and the guys above correct my mistakes lol). I am a happy guy. |
@clark-stevenson Weekly PR to the main repo, put pixi.d.ts next to pixi.js, then in the package.json: "main": "./dist/pixi.js",
"types": "./dist/pixi.d.ts" Simple as that. Then all anyone has to do is |
And why not actually do it? Most of PixiJS is pretty straightforward to convert to TypeScript. Without having looked too much at it, it seems that the only non-trivial conversion are type-annotations, and mixins, and mixins are only used for the I might be looking into converting stuff from JavaScript to TypeScript in general, and PixiJS would be a nice case. |
Guys, i need help with https://github.com/pixijs/pixi-spine . I use "tsify" to compile it, but the only way to get headers is "tsc -p tsconfig-2.json". It produces config without namespaces, and I really dont understand what should I do with it. |
Sorry I can't help Ivan. I wasn't sure myself when I looked at it. Nice to see you using TS 👍 Also thanks @paralin I have another related question for the good folks here 😄 Inside the definition file right now, is this https://github.com/pixijs/pixi-gl-core So would that mean, that pixi-gl-core would get extracted from the current definition and added to that project too? And if that is the case, how is the dependency handled between these? The fact that pixi.js.d.ts requires pixi.gl.core.d.ts |
@clark-stevenson i have to use TS because official EsotericSoftware runtime is TS now :) |
I'm of the opinion that plugin definitions don't belong in the main definition. While it's easy-ish to include the 'official' ones, it doesn't help others build typescript definitions for their own non-official plugins. The same too for dependencies - they should be split out and required/imported as needed (I'm not actually sure whether this is possible, although this looks like it might help). Were (some/all/which?) plugins to stay within the main definition, and that definition were then merged into the main pixi repo, then the main repo would also have to be responsible for reviewing/merging type definitions for those chosen plugins. As such I think that the decision on whether to merge with the main repo should be based on whether plugins and dependencies can be split out. While it's a bit verbose, and would take some effort, it looks like @webbiesdk's example is currently the only way to do this, considering there doesn't seem to be any traction on @clark-stevenson's issue here. |
What is the best way to get the most current typings for pixi.js? I have the following in my package.json:
But it seems these typings are missing |
seems like I can't install PIXI typescript above v.4.3.2.. npm install npm ERR! notarget No compatible version found: @types/pixi.js@4.4.0 |
I don't know what it means tbh. Ivan made a PR at the end of Jan which just got merged on DT. It might solve the issue and he did a lot of the grunt work. 👍❤️ There is one more PR needing made to DT to bring us into place. It is |
v4.4.0 just made it to npm: https://www.npmjs.com/package/@types/pixi.js |
So guys, I think that this will continue to be manual. The history of the file is pretty rich and it has had multiple homes. Phaser born the definition years ago where it branched off (you can see me begging in the forum when I had 1 post for a def). I am pretty happy with the definition, I mean, it is pretty accurate, and I absolutely hate coming here and looking over commit histories, but in the end.... It takes no more than an hour and over time, all of the kind folks have helped make it pretty accurate today. Furthermore there is stuff in the definition that doesn't belong there, half the dependencies are in there.... and splitting these up, the logistics of it, would be incredible and the tedium infinite. So for lack of a better plan, I am going to continue doing stuff here as usual, and pushing to DT with significant releases. If there is a V5 of Pixi, TypeScript should be considered and failing that, I would be interested at looking at creating a TS fork as it would be a hell of a lot more interesting than studying APIs! Anyway thanks for everyone answering all my questions in commit-comments about stuff over the past year or so, I learned a lot and plan more I am sure! 💃 Especially that the PR I made tonight to DT, was around 6 months old and honestly.... really not that much changed. A testament to strength of the API. 👍 |
Issue brought up in #58, moving forward, we should move the PIXI typings to the main pixi.js repo. That way the typings get locked to the distributed version of the library. Also, would ensure that when developers make PR against pixi.js that change the API, they would also need to make the corresponding API change in the typings. Thoughts?
The text was updated successfully, but these errors were encountered: