解决 store 的一些类型报错

This commit is contained in:
liaoxuezhi 2019-08-13 12:29:28 +08:00
parent 1217402b85
commit 49ed8bf570
6 changed files with 26 additions and 25 deletions

View File

@ -83,6 +83,7 @@
"@types/jest": "^24.0.11", "@types/jest": "^24.0.11",
"@types/jquery": "^3.3.1", "@types/jquery": "^3.3.1",
"@types/lodash": "^4.14.76", "@types/lodash": "^4.14.76",
"@types/node": "^12.7.1",
"@types/pretty-bytes": "^4.0.0", "@types/pretty-bytes": "^4.0.0",
"@types/prop-types": "^15.5.2", "@types/prop-types": "^15.5.2",
"@types/qs": "^6.5.1", "@types/qs": "^6.5.1",
@ -106,6 +107,9 @@
"axios": "0.18.1", "axios": "0.18.1",
"bce-sdk-js": "^0.2.9", "bce-sdk-js": "^0.2.9",
"bootstrap": "3.4.1", "bootstrap": "3.4.1",
"copy-to-clipboard": "3.0.8",
"css": "2.2.1",
"es6-symbol": "3.1.1",
"faker": "^4.1.0", "faker": "^4.1.0",
"fis-parser-node-sass": "^1.0.5", "fis-parser-node-sass": "^1.0.5",
"fis3": "^3.4.41", "fis3": "^3.4.41",
@ -131,10 +135,7 @@
"react-testing-library": "6.0.4", "react-testing-library": "6.0.4",
"strip-json-comments": "^2.0.1", "strip-json-comments": "^2.0.1",
"ts-jest": "^24.0.0", "ts-jest": "^24.0.0",
"typescript": "^3.3.4000", "typescript": "^3.3.4000"
"css": "2.2.1",
"es6-symbol": "3.1.1",
"copy-to-clipboard": "3.0.8"
}, },
"jest": { "jest": {
"testEnvironment": "jsdom", "testEnvironment": "jsdom",

View File

@ -1741,7 +1741,7 @@ export class HeadCellSearchDropDown extends React.Component<HeadCellSearchProps,
<Overlay <Overlay
container={popOverContainer || (() => findDOMNode(this))} container={popOverContainer || (() => findDOMNode(this))}
placement="left-bottom-left-top right-bottom-right-top" placement="left-bottom-left-top right-bottom-right-top"
target={popOverContainer ? () => findDOMNode(this).parentNode : null} target={popOverContainer ? () => findDOMNode(this)!.parentNode : null}
show show
> >
<PopOver <PopOver

View File

@ -74,8 +74,8 @@ export const FormItemStore = types
filteredOptions: types.optional(types.frozen(), []), filteredOptions: types.optional(types.frozen(), []),
}) })
.views(self => { .views(self => {
function getForm():IFormStore { function getForm():any {
return getParent(self, 2) as IFormStore; return getParent(self, 2);
} }
function getValue():any { function getValue():any {
@ -131,7 +131,7 @@ export const FormItemStore = types
return { return {
get form():IFormStore { get form():any {
return getForm(); return getForm();
}, },

View File

@ -1,8 +1,7 @@
import { import {
types, types,
getEnv,
getRoot, getRoot,
SnapshotIn Instance,
} from "mobx-state-tree"; } from "mobx-state-tree";
import { import {
extendObject, extendObject,
@ -25,11 +24,12 @@ export const iRendererStore = types
dialogOpen: false, dialogOpen: false,
dialogData: types.optional(types.frozen(), undefined), dialogData: types.optional(types.frozen(), undefined),
drawerOpen: false, drawerOpen: false,
drawerData: types.optional(types.frozen(), undefined), drawerData: types.optional(types.frozen(), undefined)
}) })
.views((self) => { .views((self) => {
return { return {
get parentStore():IIRendererStore | null { // todo 不能自己引用自己
get parentStore(): any {
return self.parentId && getRoot(self) && (getRoot(self) as IRendererStore).storeType === 'RendererStore' return self.parentId && getRoot(self) && (getRoot(self) as IRendererStore).storeType === 'RendererStore'
? (getRoot(self) as IRendererStore).stores.get(self.parentId) ? (getRoot(self) as IRendererStore).stores.get(self.parentId)
: null; : null;
@ -165,5 +165,5 @@ export const iRendererStore = types
export type IIRendererStore = typeof iRendererStore.Type; export type IIRendererStore = typeof iRendererStore.Type;
export type SIRendererStore = SnapshotIn<typeof iRendererStore>; export type SIRendererStore = typeof iRendererStore.SnapshotType;
// export type SIRendererStore = typeof iRendererStore.SnapshotType; // export type SIRendererStore = typeof iRendererStore.SnapshotType;

View File

@ -23,7 +23,7 @@ export const Item = types
newIndex: types.number newIndex: types.number
}) })
.views((self) => ({ .views((self) => ({
get checked() { get checked():boolean {
return (getParent(self, 2) as IListStore).isSelected(self as IItem); return (getParent(self, 2) as IListStore).isSelected(self as IItem);
}, },
@ -39,19 +39,19 @@ export const Item = types
return self.index !== self.newIndex; return self.index !== self.newIndex;
}, },
get locals() { get locals():any {
return createObject( return createObject(
createObject((getParent(self, 2) as IListStore).data, { createObject((getParent(self, 2) as IListStore).data, {
index: self.index index: self.index
}), self.data); }), self.data);
}, },
get checkable() { get checkable():boolean {
const table = (getParent(self, 2) as IListStore); const table = (getParent(self, 2) as IListStore);
return table && table.itemCheckableOn ? evalExpression(table.itemCheckableOn, (self as IItem).locals) : true; return table && table.itemCheckableOn ? evalExpression(table.itemCheckableOn, (self as IItem).locals) : true;
}, },
get draggable() { get draggable():boolean {
const table = (getParent(self, 2) as IListStore); const table = (getParent(self, 2) as IListStore);
return table && table.itemDraggableOn ? evalExpression(table.itemDraggableOn, (self as IItem).locals) : true; return table && table.itemDraggableOn ? evalExpression(table.itemDraggableOn, (self as IItem).locals) : true;
} }
@ -119,7 +119,7 @@ export const ListStore = iRendererStore
} }
return { return {
get allChecked() { get allChecked():boolean {
return !!(self.selectedItems.length === (self as IListStore).checkableItems.length && (self as IListStore).checkableItems.length); return !!(self.selectedItems.length === (self as IListStore).checkableItems.length && (self as IListStore).checkableItems.length);
}, },

View File

@ -69,7 +69,7 @@ export const Row = types
depth: types.number// 当前children位于第几层便于使用getParent获取最顶层TableStore depth: types.number// 当前children位于第几层便于使用getParent获取最顶层TableStore
}) })
.views((self) => ({ .views((self) => ({
get checked() { get checked():boolean {
return (getParent(self, self.depth * 2) as ITableStore).isSelected(self as IRow); return (getParent(self, self.depth * 2) as ITableStore).isSelected(self as IRow);
}, },
@ -81,7 +81,7 @@ export const Row = types
return Object.keys(self.data).some(key => !isEqual(self.data[key], self.pristine[key])); return Object.keys(self.data).some(key => !isEqual(self.data[key], self.pristine[key]));
}, },
get expanded() { get expanded():boolean {
return (getParent(self, self.depth * 2) as ITableStore).isExpanded(self as IRow); return (getParent(self, self.depth * 2) as ITableStore).isExpanded(self as IRow);
}, },
@ -89,19 +89,19 @@ export const Row = types
return self.index !== self.newIndex; return self.index !== self.newIndex;
}, },
get locals() { get locals():any {
return createObject( return createObject(
createObject((getParent(self, self.depth * 2) as ITableStore).data, { createObject((getParent(self, self.depth * 2) as ITableStore).data, {
index: self.index index: self.index
}), self.data); }), self.data);
}, },
get checkable() { get checkable():boolean {
const table = (getParent(self, self.depth * 2) as ITableStore); const table = (getParent(self, self.depth * 2) as ITableStore);
return table && table.itemCheckableOn ? evalExpression(table.itemCheckableOn, (self as IRow).locals) : true; return table && table.itemCheckableOn ? evalExpression(table.itemCheckableOn, (self as IRow).locals) : true;
}, },
get draggable() { get draggable():boolean {
const table = (getParent(self, self.depth * 2) as ITableStore); const table = (getParent(self, self.depth * 2) as ITableStore);
return table && table.itemDraggableOn ? evalExpression(table.itemDraggableOn, (self as IRow).locals) : true; return table && table.itemDraggableOn ? evalExpression(table.itemDraggableOn, (self as IRow).locals) : true;
} }
@ -334,7 +334,7 @@ export const TableStore = iRendererStore
return !!self.selectedRows.length; return !!self.selectedRows.length;
}, },
get allChecked() { get allChecked():boolean {
return !!(self.selectedRows.length === (self as ITableStore).checkableRows.length return !!(self.selectedRows.length === (self as ITableStore).checkableRows.length
&& (self as ITableStore).checkableRows.length); && (self as ITableStore).checkableRows.length);
}, },