Skip to content

Commit 40f3dc7

Browse files
committed
fixes for typescript 2.7
1 parent 688e3e0 commit 40f3dc7

File tree

13 files changed

+36
-26
lines changed

13 files changed

+36
-26
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"private": true,
33
"dependencies": {
4-
"lerna": "^2.4.0",
4+
"cross-env": "^5.1.1",
55
"husky": "^0.13.4",
6-
"prettier": "^1.4.4",
6+
"lerna": "^2.4.0",
77
"lint-staged": "^3.6.1",
8-
"cross-env":"^5.1.1"
8+
"prettier": "^1.4.4"
99
},
1010
"scripts": {
1111
"clean": "lerna clean",

packages/mobx-state-tree/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"tape": "^4.6.0",
5656
"tslib": "^1.7.1",
5757
"tslint": "^3.15.1",
58-
"typescript": "^2.4.2"
58+
"typescript": "^2.7.0"
5959
},
6060
"peerDependencies": {
6161
"mobx": "^3.1.15"

packages/mobx-state-tree/src/core/type/type-checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function typecheckPublic(type: IType<any, any>, value: any): void {
124124
const errors = type.validate(value, [{ path: "", type }])
125125

126126
if (errors.length > 0) {
127-
console.error("Failed to create `${type.name}` from:", value)
127+
console.error(`Failed to create "${type.name}" from:`, value)
128128
fail(
129129
`Error while converting ${shortenPrintValue(
130130
prettyPrintValue(value)

packages/mobx-state-tree/src/types/complex-types/array.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ export class ArrayType<S, T> extends ComplexType<S[], IObservableArray<T>> {
6161
return array
6262
}
6363

64-
finalizeNewInstance = (node: ObjectNode, snapshot: any) => {
65-
const instance = node.storedValue as IObservableArray<any>
66-
extras.getAdministration(instance).dehancer = node.unbox
64+
finalizeNewInstance = (node: INode, snapshot: any) => {
65+
const objNode = node as ObjectNode
66+
const instance = objNode.storedValue as IObservableArray<any>
67+
extras.getAdministration(instance).dehancer = objNode.unbox
6768
intercept(instance, change => this.willChange(change) as any)
68-
node.applySnapshot(snapshot)
69+
objNode.applySnapshot(snapshot)
6970
observe(instance, this.didChange)
7071
}
7172

packages/mobx-state-tree/src/types/complex-types/map.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ export class MapType<S, T> extends ComplexType<{ [key: string]: S }, IExtendedOb
100100
return map
101101
}
102102

103-
finalizeNewInstance = (node: ObjectNode, snapshot: any) => {
104-
const instance = node.storedValue as ObservableMap<any>
105-
extras.interceptReads(instance, node.unbox)
103+
finalizeNewInstance = (node: INode, snapshot: any) => {
104+
const objNode = node as ObjectNode
105+
const instance = objNode.storedValue as ObservableMap<any>
106+
extras.interceptReads(instance, objNode.unbox)
106107
intercept(instance, c => this.willChange(c))
107-
node.applySnapshot(snapshot)
108+
objNode.applySnapshot(snapshot)
108109
observe(instance, this.didChange)
109110
}
110111

packages/mobx-state-tree/src/types/complex-types/model.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class ModelType<S, T> extends ComplexType<S, T> implements IModelType<S,
121121
* The original object definition
122122
*/
123123
public readonly initializers: ((instance: any) => any)[]
124-
public readonly properties: { [K: string]: IType<any, any> }
124+
public readonly properties: { [K: string]: IType<any, any> } = {}
125125
private preProcessor: (snapshot: any) => any | undefined
126126
private readonly propertiesNames: string[]
127127

@@ -190,7 +190,8 @@ export class ModelType<S, T> extends ComplexType<S, T> implements IModelType<S,
190190
}
191191

192192
props<SP, TP>(
193-
properties: { [K in keyof TP]: IType<any, TP[K]> } & { [K in keyof SP]: IType<SP[K], any> }
193+
properties: { [K in keyof TP]: IType<any, TP[K]> | TP[K] } &
194+
{ [K in keyof SP]: IType<SP[K], any> | SP[K] }
194195
): IModelType<S & SP, T & TP> {
195196
return this.cloneAndEnhance({ properties } as any)
196197
}
@@ -309,15 +310,16 @@ export class ModelType<S, T> extends ComplexType<S, T> implements IModelType<S,
309310
return instance as Object
310311
}
311312

312-
finalizeNewInstance = (node: ObjectNode, snapshot: any) => {
313-
const instance = node.storedValue as IStateTreeNode
313+
finalizeNewInstance = (node: INode, snapshot: any) => {
314+
const objNode = node as ObjectNode
315+
const instance = objNode.storedValue as IStateTreeNode
314316
this.forAllProps((name, type) => {
315317
extendShallowObservable(instance, {
316318
[name]: observable.ref(
317-
type.instantiate(node, name, node._environment, snapshot[name])
319+
type.instantiate(objNode, name, objNode._environment, snapshot[name])
318320
)
319321
})
320-
extras.interceptReads(instance, name, node.unbox)
322+
extras.interceptReads(instance, name, objNode.unbox)
321323
})
322324

323325
this.initializers.reduce((self, fn) => fn(self), instance)
@@ -493,10 +495,10 @@ export function model<T = {}>(properties?: IModelProperties<T>): IModelType<Snap
493495
* @export
494496
* @alias types.model
495497
*/
496-
export function model(...args: any[]) {
498+
export function model<T = {}>(...args: any[]): IModelType<Snapshot<T>, T> {
497499
const name = typeof args[0] === "string" ? args.shift() : "AnonymousModel"
498500
const properties = args.shift() || {}
499-
return new ModelType({ name, properties })
501+
return new ModelType({ name, properties }) as IModelType<Snapshot<T>, T>
500502
}
501503

502504
export function compose<T1, S1, T2, S2, T3, S3>(

packages/mobx-state-tree/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function extendKeepGetter(a: any, ...b: any[]) {
5151
for (let i = 0; i < b.length; i++) {
5252
const current = b[i]
5353
for (let key in current) {
54-
const descriptor = Object.getOwnPropertyDescriptor(current, key)
54+
const descriptor = Object.getOwnPropertyDescriptor(current, key)!
5555
if ("get" in descriptor) {
5656
Object.defineProperty(a, key, { ...descriptor, configurable: true })
5757
continue

packages/mobx-state-tree/test/action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ test("snapshot should be available and updated during an action", t => {
258258
const a = Model.create({ x: 2 })
259259
t.is(a.inc(), 3)
260260
t.is(a.x, 4)
261-
t.is(getSnapshot(a).x, 4)
261+
t.is(getSnapshot<typeof Model.SnapshotType>(a).x, 4)
262262
})
263263

264264
test("indirectly called private functions should be able to modify state", t => {

packages/mobx-state-tree/test/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,5 @@ test("snapshot processors can be composed", t => {
242242
}))
243243
const x = X.create({ x: 25 })
244244
t.is(x.x, 2)
245-
t.is(getSnapshot(x).x, 25)
245+
t.is(getSnapshot<typeof X.SnapshotType>(x).x, 25)
246246
})

packages/mobx-state-tree/test/optimizations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test("it should avoid processing patch if is exactly the current one in reconcil
2424
})
2525
const store = RootModel.create({ a: { a: 1, b: "hello" } })
2626
unprotect(store)
27-
const snapshot = getSnapshot(store)
27+
const snapshot = getSnapshot<typeof Model.SnapshotType>(store)
2828
store.a = snapshot.a
2929
t.is(getSnapshot(store.a), snapshot.a)
3030
t.deepEqual(getSnapshot(store), snapshot)

0 commit comments

Comments
 (0)