Closed imanabu closed 7 years ago
Good point, when stream is used as a script it's added to the global m
. I'll work on a fix.
Looking into this, it's going to be a tricky problem to solve for the next mithril release.
As for the current version of mithril and the type definitions, I think it's about as correct as it can get. The stream type is available from stream.Stream
and all static methods are available on the global stream
object.
With the next release however, the types will differ between module and script distributions. When used as a script, you will have an m
global and when you add the stream script, you will have m.stream
. With modules, you'll import * as m from 'mithril'
and import * as stream from 'mithril/stream'
. I don't see a way to create unified definitions for stream.
At best I think we'll need to provide a separate .d.ts for script usage which would not be distributed via DefinitelyTyped (i.e., you'd need to download the types file and put it in your project.)
@imanabu For your own convenience, I would strongly consider using modules by adding a bundler to your build. I have some example project repos that use minimal tooling.
@andraaspar have you got any other ideas on how to deal with the script/module variants?
OK. @spacejack Thank you for the thoughts on this. I think that most modern use of JS has been to use a bundler and I myself have to move to that. The Git download method is perfectly fine, so long as they are well documented. Let's close this and I will help keep that documented.
@imanabu Cool. If you need help with tooling you can ping me on Gitter. I'll leave the issue open as a reminder however because it shouldn't be too hard to create a script version in another repo.
@spacejack, Started on browserify now, it's working great so far and started Mithril Typescript Cookbook https://github.com/imanabu/MithrilTypeScriptCookbook/wiki Not making wide announcement until it is a bit more comprehensive.
Merging UMD declarations is blocked by https://github.com/Microsoft/TypeScript/issues/12106. Until a fix lands there, the best we can do is merge the stream declaration into the main index.d.ts.
I think the best option is to create a separate repo (or branch) for global usage. It would contain a single .d.ts file tailored to having everything on the global m
.
This might be needed anyway in the case that you're writing modules but using mithril.js as a script file.
At this point streams's index.d.ts exists in @types/mithril/stream
The #improved has moved the stream interfaces under the mihtril / stream and this breaks global style usage.
This would probably work in "module" style, but it cannot be pulled as an "environmental" global declaration. I understand that if I explicitly import this, it will make that source file a "module" which has other implications.
I was able to fix this by moving the stream folder to the top level of @Types manually.
Recommendation: If it is going to be separated, perhaps, the best approach is to have another repository for this purpose or consolidate it like it used to be?