Commit graph

53 commits

Author SHA1 Message Date
spacejack
b3615aa607 Add class and factory component type definitions. Add JSDoc comments to types. 2017-02-18 08:44:01 -05:00
spacejack
1e879963f1 Add Typescript definitions 2017-02-14 20:26:15 -05:00
Leo
1620b147da clean up repo 2017-01-30 11:18:47 -05:00
cetra3
7fc0e0378c Allow Request Headers to be set via config (#1464)
Fixes #1463.
2016-12-30 01:33:13 -05:00
valtron
bc2b3c5fdc Fix #1379 (#1398) 2016-11-15 12:44:46 -08:00
András Parditka
5e1552b1ee Fixed #1343, #1336. (#1383) 2016-11-03 09:27:58 -07:00
impinball
cb10456bbe Add definition file to npm [ci skip] 2016-06-17 06:09:04 -04:00
impinball
89165e9cab Fix documentation nit 2016-04-02 15:51:38 -04:00
impinball
26b8a029f5 Clean up Promise/Thenable types, remove PromiseProperty type. 2016-04-02 13:55:14 -04:00
impinball
d9aa3111bf Dedupe vdom factories, fix args for vdom methods + {build,parse}QueryString
Also, add recursive Children type.
2016-04-02 12:31:40 -04:00
impinball
d3753aea43 Set up m.request types for XHROptions and JSONPOptions 2016-03-28 06:36:02 -04:00
impinball
26af09a017 Change some types to string unions, make m.redraw.strategy a BasicProperty<T>
In the latter case, the type already structurally satisfied that type.
Changing m.redraw.strategy simplifies the definition file, and aligns with
the docs.
2016-03-22 10:39:30 -04:00
impinball
490a5c7b73 Remove useless generics, fix VirtualElement members, fix a few style issues 2016-03-22 09:28:00 -04:00
LabEG
c9899d5e07 Remove ugly alias for m 2016-03-16 22:18:26 +03:00
LabEG
7f5d42e08c Resolve conflict after pull request #983 2016-03-16 22:11:28 +03:00
LabEG
06ec4b6fad Remove generic from MithrilVirtualElement. Because him unused.
Rename module to namespace. Module is deprecated.
2016-03-14 22:24:08 +03:00
Alexander Lindsay
40130c1cc5 Switched to using a union type
Changed T to T | MithrilPromise<T> in the MithrilPromise and
MithrilPromiseProperty definitions
2016-02-22 17:55:54 -08:00
Alexander Lindsay
b0b727ff73 Fix definition of MithrilPromise
MithrilPromise returns the value it holds and not another promise that
holds the value. MithrilPromiseProperty was adjusted to act as a nested
MithrilPromise.
2016-02-21 10:45:13 -08:00
pixelmike
4a53a49b89 Added an overload for withAttr. Added parameters to component controller and view functions. 2016-01-30 12:22:01 -05:00
Max Lang
d770f29e39 update typescript defs to support broader MithrilAttributes 2016-01-12 11:00:44 -05:00
Isiah Meadows
6a160dc10f Degenerify MithrilRoutes
The routes type doesn't need to be parametrized. It's far too restricting and technically incorrect.
2015-12-30 20:42:57 -05:00
Leo Horie
270b20a2b0 v0.2.2-rc.1 2015-12-20 09:14:28 -05:00
Sean Hussey
c1912d2726 Fixing a few typos. Changing all instances of "thennable" to
"thenable". No functional changes.
2015-12-18 14:40:41 -05:00
Matt Tracy
da6d525a11 Typescript: Make MithrilVirtualElement non-generic
`MithrilVirtualElement` was recently converted to be generic over `<T extends
MithrilController>`. The element's `children` may then contain other
`MithrilVirtualElement<T>` or `MithrilComponent<T>` elements.

Unfortunately, in common usage of 'm()' this can cause problems with Mithril's type
inference system. If a type is not explicitly provided to `m()`, the "T" of the
returned MithrilVirtualElement<T> will be inferred from its children. The
candidates for T will be the concrete types of the child MithrilComponent<T>; however, if no
candidate type is a subset of *every* candidate type, then TypeScript will be
unable to infer a valid type, and the call to `m()` will not compile.

To improve this behavior, this commit makes MithrilVirtualElement non-generic;
it's child collection can now contain MithrilComponent<MithrilController>, which
matches all valid MithrilComponent. This the same underlying issue as the
previous commit, which made MithrilRoutes non-generic.

The motivation for fixing this is threefold:

1. Because `m()` has so many overloads, in the case where a call to `m()` will
not compile due to the above issue, the syntax error provided by TypeScript is
not helpful.
2. In many cases, users will be calling `m<MithrilController>()` in their code
simply to get it to compile, which provides no additional utility over a
non-generic type and adds significant boilerplate.
3. Explicitly specifying subtypes to `m()` calls provides little utility; at
best, it can check that contained components implement some common interface.
However, type assertions like that can be provided in other places without
having to attach the information to the MithrilVirtualElement.
2015-10-14 17:27:22 -04:00
Matt Tracy
26f68744b5 Improve Typescript definition for MithrilRoutes
The previous definition of MithrilRoutes was generic over <T extends
MithrilController>, with the MithrilRoutes containing a collection of
MithrilComponent<T>.

However, this presents problems with TypeScript's type inference in many common
situations.  For example, consider this usage of m.route():

```
m.route(document.body, "/a", {
    "/a": ComponentA,
    "/b": ComponentB,
})
```
Both `ComponentA` and `ComponentB` implement `MithrilComponent<T extends
MithrilController>`, with each component having a different concrete controller
type (`ControllerA` and `ControllerB`).

However, unless ControllerA's type is a subset of ControllerB's type (or
vice-versa), TypeScript will be unable to infer the type of the MitrilRoutes<T>
returned by m.route(). To get this to compile, a third type which *is* a
subset of both ControllerA and ControllerB would need to be explicity provided:

```
// Both ControllerA and ControllerB implement MithrilController
m.route<MithrilController>(document.body, "/a", {
  "/a": ComponentA,
  "/b": ComponentB,
})
```

This commit makes MithrilRoute non-generic, and instead of containing
MithrilComponent<T extends MithrilRoute>, it contains
MithrilComponent<MithrilController>, which will match all valid
MithrilComponents.

The motivation for this change is twofold:

1. In the case where m.route() does not compile due to type-inference failure,
the resulting syntax error from Typescript is very unhelpful because m.route()
has a number of overloads. Leaving this as is will result in confusion for
downstream users.
2. An assumption that vanishingly little utility is provided by defining
`MithrilRoutes<T extends MithrilController>` over a type more specific than
MithrilController. At most, it could be used to assert that all of your routed
Components meet a more specialized interface, but that same type check could be
accomplished without having to augment MithrilRoutes with that information.
2015-10-14 17:24:19 -04:00
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