Need a definition type
You could generate a definition file and serve it along the npm package. Then you can use $ tsd link to use it in your project.
I agree. Would be nice to have TS defs. Seems like there is some consensus around this being the best way to build an ng2 related lib: https://medium.com/@OCombe/how-to-publish-a-library-for-angular-2-on-npm-5f48cdabf435
Kind of out of time these days, but will try to do that soon.
No rush. The ng2 best practices are, shall we say, fluid. :p
:+1:
+1
Hey guys,
Sorry for the huge delay regarding this issue.
I just created PR #22 that implement a basic typing for ng2-redux and updated the sample app to use it.
Feedback on this is very welcome since I don't consider myself an expert in TypeScript definition files :)
Thanks
tl;dr I am happy to help with d.ts files, including the redux.d.ts files in DefinitelyTyped...
Long version:
Over the week-end I was playing with a bunch of redux/Angular 2 stuff. I went way overboard though, and I ported this library to TypeScript, which is overkill, and probably not what you want, but I wanted to see if I could transform your binding system such that it uses decorators, like:
@component({
// component details
})
@connect({
bindState: (state) => {
return {
counter: state.counter
}
},
bindDispatch: (dispatch) => {
return bindActionCreators<any,
CounterActions.ICounterDispatch>(CounterActions, dispatch);
}
})
class SomeContainer implements OnDestroy {
// container/component logic
}
The idea is that the decorator function handles all the subscribe/unsubscribe boiler plate.
I do not have a copy of the decorator working yet, I hit some dependency issues, and there might also be issues trying to Inject('ngRedux') from within the decorator.... However, the TypeScript port does work, including with the counter example, my fork is here: https://github.com/bennett000/ng2-redux/tree/typescript
I should also point out that the TypeScript stuff I did depends on a copy of redux.d.ts that uses generics... I built my redux.d.ts on @wbuchwalter's base from Definitely typed. I have a PR for it in DefinitelyTyped, but there are complications, b/c other redux related typings in DT depend on wbuchwalter's original...
I'm happy to help sort out all of those DefinitelyTyped issues, and help with typing ng2-redux
Also if you're interested in the TypeScript fork let me know, I can work towards cleaning it up, and getting it into shape for a PR. For the record the tests are passing, and the example works on Ubuntu 12.04, but I'd like to do fresh npm installs, and make sure I didn't introduce any dependency issues...
update Here's a link to the redux.d.ts typings I was working on with generic support: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/7672/files
Hey Michael, Really nice work!
The decorator you did is pretty much what I had in mind (I talked with @e-schultz about this), so we are in sync there.
Regarding redux.d.ts, I guess you already saw it, but there is already a PR on DefinitlyTyped that would bring generics, but it's pretty much in limbo since every contributor of every dependent typing needs to validate it...
I don't know if DT's maintainer would be ok with just adding the version at the end of the file like you did (since it's in fact the same version), but I guess it's worth a shot.
Regarding migrating ng2-redux to TypeScript, the only downside I see is that it could potentially intimidate contributors who are not familiar with it, but I guess the percentage of people coding with angular2 and not knowing TS will be fairly low, so that may be a false problem.
On the other hand it would remove any risk of mismatch between the typings and the actual implementation, so I'm open to this idea.
@wbuchwalter that PR is way more comprehensive. I closed my PR. I did keep up a PR for invariant, which is used by ng2-redux.
I still haven't read the full body of the PR, but I did notice some (potential) issues with the d.ts files, at least with respect to DefinitelyTyped's contribution guide. Notably the use of class. The DT people (at least at one point in time) were really concerned about "Ghost Modules".
I will digest the body of the PR a little later and figure out the details, maybe it will be possible for me to coordinate with xogeny.
On the topic of ng2-redux, and the decorator interface, if you're not aware, I am currently working with @e-schultz , which is where I got the idea for the @Connector style interface.
With respect to TypeScript I think your concern about it intimidating some contributors is reasonable. There's also people who for one reason or another do not like TypeScript. IMO it doesn't help that it's branded as a classical OOP tool.
Like your other hand comment, TypeScript does fit with Angular 2's direction, and the typing mismatch would be eliminated. In addition there's no reason the code could not maintain a strong es6 style. It's even possible to use babel, and tsc in the same project with both webpack, and mocha.
The TypeScript fork I have is pretty much just renamed files, and type contracts at the end points. Essentially whatever the minimum I could do to get tests to pass, the example to run. All so I could play with the decorator implementation, which I'm sure could be done without TypeScript; decorators are just functions. I also wanted to figure out redux from a few different angles, and how it fits with Angular 2, so I'm having fun.
So do we have a typings available for this yet?
@AjinkyaKher there is an alternate branch with the latest TypeScript work, so yes that will include typings. I'm not sure where we stand with getting that branch merged but I will hopefully be able to answer that by early to mid next week.
@AjinkyaKher I still do not know when the merge will happen, but a few of us have been chipping away at new TS features. The test suite has been upgraded to TS, the examples are working on Beta 13 now, and we've got an observable store feature in the works.
@AjinkyaKher v2.2.3 has been released which has type definitions and using the official redux types.
Hi all,
Version 2.2.3 has been release and has been rebuilt in Typescript. So it how has comprehensive typings as part of the lib.
is there a way to include the typings with the npm package? I am running this on a closed system so that server only has access out to npm (though a proxy) and since this tries to run a typings install after the package is installed it is breaking my build process.