Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

DefinitelyTyped release #13

Closed
spacejack opened this issue Mar 25, 2017 · 20 comments
Closed

DefinitelyTyped release #13

spacejack opened this issue Mar 25, 2017 · 20 comments

Comments

@spacejack
Copy link
Collaborator

spacejack commented Mar 25, 2017

@andraaspar: It looks like Mithril 1.1 will be released on Monday, so I'd like to prepare a PR for DefinitelyTyped that's ready to go when mithril releases.

Stream layout has changed a bit - scan and scanMerge functions are now included in stream rather than separate modules.

I'm going to rename tests to test. Convention seems to be either put all tests in module-tests.ts or to include a test folder.

To do this I'm going to fork improved (which should remain compatible with the current mithril 1.0.1 release) to dt-umd.

@spacejack
Copy link
Collaborator Author

Please see the new dt-umd branch.

@andraaspar
Copy link
Contributor

@spacejack You said that you would ultimately want a UMD version and a ES6 module version. Are you still aiming for that?

@spacejack
Copy link
Collaborator Author

I think what we want is this UMD version and a global version for scripts?

I'm going to try a global version that imports the UMD types then exports some customized global types so we don't have to copies of everything. Eg., building on this idea.

@spacejack
Copy link
Collaborator Author

Oops I think I missed your point... I suppose these types don't need to be UMD since they're not correct for global usage, they only need to work for module usage. So should probably remove the export as namespace m;

@andraaspar
Copy link
Contributor

That line means the difference between m.Comp and Mithril.Comp, right? Maybe it should be consistent in both versions. The latter seems to be a better option.

@spacejack
Copy link
Collaborator Author

Well the module version should be whatever name you use. So if you import * as m from 'mithril' then everything is attached to m. If you import * as mithril from 'mithril' then it's mithril.Comp etc.

For the global version, everything should be on m because m is the global exported from the mithril.js script.

I'm playing around with a global version of types, but can't quite get it to work... I was hoping something like...

import * as mithril from 'mithril';
import * as stream from 'mithril/stream';

declare const m: mithril.Static & stream.Static;

@spacejack
Copy link
Collaborator Author

Also trying this but it's not working, hmm...

import * as mithril from 'mithril';

declare namespace Mithril {
	type Lifecycle<A,S> = mithril.Lifecycle<A,S>;
	type Hyperscript = mithril.Hyperscript;
	type RouteResolver<S,P> = mithril.RouteResolver<S,P>;
	...
}

declare const m: Mithril.Static;

@spacejack
Copy link
Collaborator Author

spacejack commented Mar 26, 2017

All right, I think I have it. This seems to work:

// mithril-global.d.ts
import * as mithril from 'mithril';
import * as stream from 'mithril/stream';

declare global {
	namespace Mithril {
		type Lifecycle<A,S> = mithril.Lifecycle<A,S>;
		type Hyperscript = mithril.Hyperscript;
		type RouteResolver<S,P> = mithril.RouteResolver<S,P>;
		...
		type Stream<T> = stream.Stream<T>;
		type Static = mithril.Static & {stream: stream.Static};
	}
	const m: Mithril.Static;
}

Then usage is:

// test.ts
let c: Mithril.Component<{},{}>
m(c, ...)
let s: Mithril.Stream<number> = m.stream(1)

@spacejack
Copy link
Collaborator Author

Ugh, no, we should be using UMD style for global usage. Sigh...

// mithril-global.d.ts
import * as mithril from 'mithril';
import * as stream from 'mithril/stream';

declare namespace Mithril {
	export type Lifecycle<A,S> = mithril.Lifecycle<A,S>;
	export type Hyperscript = mithril.Hyperscript;
	export type RouteResolver<S,P> = mithril.RouteResolver<S,P>;
	//...
	export type Stream<T> = stream.Stream<T>;
	export type Static = mithril.Static & {stream: stream.Static};
}

declare const Mithril: Mithril.Static;
export = Mithril;
export as namespace m;

Script usage:

// test.ts
let c: m.Component<{},{}>
m(c, ...)
let s: m.Stream<number> = m.stream(1)

Now you have minimal differences between script and module app code.

@andraaspar
Copy link
Contributor

How about importing with /// <reference path="..."/>?

@spacejack
Copy link
Collaborator Author

I have created a new branch: dt-module which is now exclusively for module use. (This simply removed the export as namespace... lines and updates the readme.)

On the mithril-global.d.ts repo, I've created the branch dt-global. Installable with npm install -D github:spacejack/mithril-global.d.ts#dt-global

Finally, here is a test repo for the global types.

This repo includes a small but necessary additional types file in the case that you are writing modules but are including mithril.js as a standalone script file. See the test.ts file for notes on the nuances.

This accommodates all 3 forms of usage as best as I can see at this point.

Let me know if you think there are any possible improvements yet.

@andraaspar
Copy link
Contributor

@spacejack Looks great!

@winksaville
Copy link

Previously you'd indicated that mithril.d.ts was going to be moved into mithrild.js project itself, is that still on the road map?

@spacejack
Copy link
Collaborator Author

Hi @winksaville, sorry, plans have changed. We'll be submitting to DefinitelyTyped instead. It will be easier to maintain if the release cycles are decoupled, plus makes it easier to switch between type definitions if a user prefers.

These are the types that will be submitted: https://github.com/spacejack/mithril.d.ts/tree/dt-module

and for now can be installed with:

npm install -D github:spacejack/mithril.d.ts#dt-module

@winksaville
Copy link

winksaville commented Mar 27, 2017 via email

@spacejack
Copy link
Collaborator Author

Mithril 1.1 was released today. I've merged the working branches into master for mithril.d.ts and mithril-global.d.ts. See the readmes in the respective repos for current install urls.

Time permitting, I'll try to prepare a PR for DefinitelyTyped tomorrow.

@winksaville
Copy link

winksaville commented Mar 28, 2017 via email

@spacejack
Copy link
Collaborator Author

Well, trigger pulled! PR is here.

Had to make some organizational and config changes to conform to DT's repo. Would like to roll those changes back into this repo in order to make future work easier to create PRs for.

@winksaville It's up to you. I don't think there are any plans to change the definitions unless DT rejects us for some reason. So you should be able to simply switch your package.json to point from here to npm. I'm not sure how long it'll be before the new types appear on npm assuming the PR is merged, but I'm sure several days at least(?)

@winksaville
Copy link

winksaville commented Mar 29, 2017 via email

@spacejack
Copy link
Collaborator Author

Types have been merged! You can now install from npm with:

npm install -D @types/mithril

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

No branches or pull requests

3 participants