Commit graph

28 commits

Author SHA1 Message Date
Matt Tracy
1cdb66b20d Typescript: Support for Parameterized Components
Previously, the Typescript definition file did not support parameterized
components. The `component()` function did accept additional arguments, but the
`MithrilComponent<T>` interface did not allow components to have any additional
arguments in either their `controller()` or `view()` methods.

Properly supporting flexible variadic parameters in typescript is somewhat
challenging. Tuple types are close, but would only work if the signature of
`controller` and `view` accepted arrays of arguments:
```
interface MithrilStatic {
  component<TController extend controller, TRest extends any[]>(
    component: ParameterizedMithrilComponent<TController, TRest>,
    ...args:TRest
  ) : TController
}

interface ParameterizedMithrilComponent<TController extend controller, TRest
extends any[]> {
  // Doesn't match mithril's component interface; we want to unpack the contents
  // of TRest
  controller: (args: TRest) => TController,
  view: (ctrl: TController, args: TRest)
}
```

Therefore, I have gone with a more traditional method of defining several
overloads of m.component(), each with a different number of extra parameters.
Because of this, the first four parameters to m.component() will be correctly
type checked (i.e. if the Component's controller defines the parameter, it must
be supplied to m.component). Additional parameters beyond the first four are
allowed, but are caught via an `...args:any[]` and thus are not type checked.
2015-09-30 16:44:45 -04:00
Leo Horie
ed3f3f0686 document component shorthand syntax 2015-07-23 23:43:19 -04:00
impinball
51f59419b2 Strengthen types, describe API in TypeScript file 2015-07-09 09:41:15 -04:00
impinball
d4848c0379 Remove trailing whitespace 2015-07-09 03:38:42 -04:00
Leo Horie
ea8853eec2 fix compile errors in ts file 2015-04-28 22:48:31 -04:00
Blayne Chard
23be76e03f Fixing TS1016: A required parameter cannot follow an optional parameter 2015-04-29 11:54:19 +12:00
Leo Horie
f0b20da30a update docs about config: m.route 2015-04-22 20:32:39 -04:00
Leo Horie
aa541bff79 document vdom arg in config 2015-04-10 22:32:54 -04:00
Leo Horie
b84fb1b40c Merge branch 'next' into components 2015-03-26 22:27:43 -04:00
Leo Horie
bcc8f427a1 update typescript definition 2015-03-26 22:27:31 -04:00
Leo Horie
9ada8111d7 Merge branch 'next' into components
Conflicts:
	mithril.d.ts
2015-03-25 22:07:11 -04:00
Leo Horie
577d0f7039 #506 allow AMD modules to load from typescript 2015-03-24 20:45:43 -04:00
Leo Horie
8fadeadb8f some docs 2015-02-18 21:59:54 -05:00
Chris Bowdon
130a075a91 Fixed weird 7-space indentation in d.ts (now 4) 2015-02-14 13:32:34 +00:00
Chris Bowdon
a5667ff341 Made it possible to use TypeScript class as a controller 2015-02-14 13:31:50 +00:00
Chris Bowdon
492eb2ed67 Stricter TypeScript definitions 2015-02-11 20:51:48 +00:00
Leo Horie
22795fb59b update ts file 2015-01-19 23:27:47 -05:00
Blayne Chard
03fe9c4edc Updating typescript redraw definition to allow m.redraw.strategy 2014-12-04 10:59:05 +13:00
Blayne Chard
5b71027896 Updating typescript route definition to allow m.route.mode and m.route.param(key). 2014-12-03 11:28:50 +13:00
Chris Bowdon
2ec0e5e0c2 Added declaration for TypeScript external module support 2014-11-15 11:02:44 +00:00
Leo Horie
eceea4addf document deps 2014-09-20 16:55:57 -04:00
zzmp
ab92e0e05f added typescript definition of m.deps 2014-09-17 20:39:21 -07:00
Leo Horie
7fb6146ecc Merge branch 'typescript_defs_no_implicit_any' of github.com:cbowdon/mithril.js into cbowdon-typescript_defs_no_implicit_any
Conflicts:
	mithril.d.ts
2014-09-14 01:04:10 -04:00
C. James Winslow
343687d5f2 update typescript definition 2014-09-10 16:19:43 -07:00
Chris Bowdon
b7cdeaf46e TypeScript defs: module can actually take a Node 2014-09-08 08:21:47 +08:00
Chris Bowdon
7948ef9be5 TypeScript defs: added return types where missing from MithrilXHROptions. 2014-09-07 18:00:39 +08:00
Leo Horie
bdcfbde8e0 document new argument in m.route(path) 2014-05-25 23:52:46 -04:00
Leo Horie
0d10046a3e add typescript definition file 2014-05-15 22:52:28 -04:00