Skip to content

Commit d687833

Browse files
authored
fix ts 3.5 regression, Fixes #1348 (#1353)
* fix ts 3.5 regression * further fixes * some more improvements while at it * code review fixes
1 parent 79502b5 commit d687833

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

packages/mobx-state-tree/src/core/mst-operations.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import {
3030
assertArg,
3131
assertIsValidIdentifier,
3232
IActionContext,
33-
getRunningActionContext
33+
getRunningActionContext,
34+
IAnyComplexType
3435
} from "../internal"
3536

3637
/** @hidden */
@@ -44,7 +45,7 @@ export type TypeOrStateTreeNodeToStateTreeNode<
4445
* @param object
4546
* @returns
4647
*/
47-
export function getType(object: IAnyStateTreeNode): IAnyType {
48+
export function getType(object: IAnyStateTreeNode): IAnyComplexType {
4849
assertIsStateTreeNode(object, 1)
4950

5051
return getStateTreeNode(object).type
@@ -380,7 +381,7 @@ export function hasParent(target: IAnyStateTreeNode, depth: number = 1): boolean
380381
* @param depth How far should we look upward? 1 by default.
381382
* @returns
382383
*/
383-
export function getParent<IT extends IAnyStateTreeNode | IAnyType>(
384+
export function getParent<IT extends IAnyStateTreeNode | IAnyComplexType>(
384385
target: IAnyStateTreeNode,
385386
depth = 1
386387
): TypeOrStateTreeNodeToStateTreeNode<IT> {
@@ -404,7 +405,7 @@ export function getParent<IT extends IAnyStateTreeNode | IAnyType>(
404405
* @param type
405406
* @returns
406407
*/
407-
export function hasParentOfType(target: IAnyStateTreeNode, type: IAnyType): boolean {
408+
export function hasParentOfType(target: IAnyStateTreeNode, type: IAnyComplexType): boolean {
408409
// check all arguments
409410
assertIsStateTreeNode(target, 1)
410411
assertIsType(type, 2)
@@ -424,7 +425,7 @@ export function hasParentOfType(target: IAnyStateTreeNode, type: IAnyType): bool
424425
* @param type
425426
* @returns
426427
*/
427-
export function getParentOfType<IT extends IAnyType>(
428+
export function getParentOfType<IT extends IAnyComplexType>(
428429
target: IAnyStateTreeNode,
429430
type: IT
430431
): IT["Type"] {
@@ -449,7 +450,7 @@ export function getParentOfType<IT extends IAnyType>(
449450
* @param target
450451
* @returns
451452
*/
452-
export function getRoot<IT extends IAnyType | IAnyStateTreeNode>(
453+
export function getRoot<IT extends IAnyComplexType | IAnyStateTreeNode>(
453454
target: IAnyStateTreeNode
454455
): TypeOrStateTreeNodeToStateTreeNode<IT> {
455456
// check all arguments
@@ -523,7 +524,7 @@ export function resolvePath(target: IAnyStateTreeNode, path: string): any {
523524
* @param identifier
524525
* @returns
525526
*/
526-
export function resolveIdentifier<IT extends IAnyType>(
527+
export function resolveIdentifier<IT extends IAnyModelType>(
527528
type: IT,
528529
target: IAnyStateTreeNode,
529530
identifier: ReferenceIdentifier
@@ -814,12 +815,12 @@ export interface IModelReflectionPropertiesData {
814815
export function getPropertyMembers(
815816
typeOrNode: IAnyModelType | IAnyStateTreeNode
816817
): IModelReflectionPropertiesData {
817-
let type
818+
let type: IAnyModelType
818819

819820
if (isStateTreeNode(typeOrNode)) {
820821
type = getType(typeOrNode) as IAnyModelType
821822
} else {
822-
type = typeOrNode
823+
type = typeOrNode as IAnyModelType
823824
}
824825

825826
assertArg(type, t => isModelType(t), "model type or model instance", 1)

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
AnyNode,
1111
IAnyType,
1212
IType,
13-
assertArg
13+
assertArg,
14+
STNValue,
15+
Instance,
16+
IAnyComplexType
1417
} from "../../internal"
1518

1619
/**
@@ -52,7 +55,7 @@ export type TypeOfValue<T extends IAnyStateTreeNode> = T extends IStateTreeNode<
5255
* Represents any state tree node instance.
5356
* @hidden
5457
*/
55-
export interface IAnyStateTreeNode extends IStateTreeNode<IAnyType> {}
58+
export interface IAnyStateTreeNode extends STNValue<any, IAnyType> {}
5659

5760
/**
5861
* Returns true if the given value is a node in a state tree.
@@ -62,9 +65,9 @@ export interface IAnyStateTreeNode extends IStateTreeNode<IAnyType> {}
6265
* @param value
6366
* @returns true if the value is a state tree node.
6467
*/
65-
export function isStateTreeNode<IT extends IAnyType = IAnyType>(
68+
export function isStateTreeNode<IT extends IAnyComplexType = IAnyComplexType>(
6669
value: any
67-
): value is IStateTreeNode<IT> {
70+
): value is STNValue<Instance<IT>, IT> {
6871
return !!(value && value.$treenode)
6972
}
7073

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export enum TypeFlags {
5959
export const cannotDetermineSubtype = "cannotDetermine"
6060

6161
/**
62+
* A state tree node value.
6263
* @hidden
6364
*/
6465
export type STNValue<T, IT extends IAnyType> = T extends object ? T & IStateTreeNode<IT> : T

0 commit comments

Comments
 (0)