Skip to content

Bnaya iteration #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
import { IModelType, Instance, _NotCustomized, ISimpleType } from "mobx-state-tree";
export declare const ModelA: IModelType<{
declare const ModelAInferred: IModelType<{
foo: ISimpleType<string>;
}, {}, _NotCustomized, _NotCustomized>;
export declare type ModelAStoreType = Instance<typeof ModelA>;
export interface IModelAStore extends ModelAStoreType {
type ModelAFactoryType = typeof ModelAInferred;
interface ModelAFactoryInterface extends ModelAFactoryType {
}
export declare const ModelB: IModelType<{
a: IModelType<{
foo: ISimpleType<string>;
}, {}, _NotCustomized, _NotCustomized>;
export declare const ModelA: ModelAFactoryInterface;
export interface IModelAStore extends Instance<ModelAFactoryInterface> {
}
declare const ModelBInferred: IModelType<{
a: ModelAFactoryInterface;
}, {}, _NotCustomized, _NotCustomized>;
export declare type ModelBStoreType = Instance<typeof ModelB>;
export interface IModelBStore extends ModelBStoreType {
type ModelBFactoryType = typeof ModelBInferred;
interface ModelBFactoryInterface extends ModelBFactoryType {
}
export declare const ModelB: ModelBFactoryInterface;
export interface IModelBStore extends Instance<ModelBFactoryInterface> {
}
declare type HardCodedModelType = IModelType<{
a: typeof ModelA;
declare const ModelCInferred: IModelType<{
b: ModelBFactoryInterface;
}, {}, _NotCustomized, _NotCustomized>;
export declare const ModelC: HardCodedModelType;
export declare type ModelCStoreType = Instance<typeof ModelC>;
export interface IModelCStore extends ModelCStoreType {
type ModelCFactoryType = typeof ModelCInferred;
interface ModelCFactoryInterface extends ModelCFactoryType {
}
export declare const ModelC: ModelCFactoryInterface;
export interface IModelCStore extends Instance<ModelCFactoryInterface> {
}
declare const ModelDInferred: IModelType<{
b: ModelBFactoryInterface;
} & {
foo: ISimpleType<string>;
}, {}, _NotCustomized, _NotCustomized>;
type ModelDFactoryType = typeof ModelDInferred;
interface ModelDFactoryInterface extends ModelDFactoryType {
}
export declare const ModelD: ModelDFactoryInterface;
export interface IModelDStore extends Instance<ModelDFactoryInterface> {
}
export {};
14 changes: 0 additions & 14 deletions dist/index.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.js.map

This file was deleted.

67 changes: 49 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"author": "",
"license": "ISC",
"dependencies": {
"mobx": "^5.15.0",
"mobx-state-tree": "^3.15.0",
"typescript": "^3.7.2"
"mobx": "^6.9.0",
"mobx-state-tree": "^5.1.8",
"typescript": "^5.1.6"
},
"devDependencies": {
"@types/node": "^12.12.9"
"@types/node": "^20.3.3"
}
}
48 changes: 26 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,41 @@ import {
IModelType,
Instance,
_NotCustomized,
ISimpleType
ISimpleType,
} from "mobx-state-tree";

export const ModelA = t.model({
const ModelAInferred = t.model({
foo: t.string
});

export type ModelAStoreType = Instance<typeof ModelA>;
export interface IModelAStore extends ModelAStoreType {}

// Typical MST usage with inferred type
export const ModelB = t.model({
type ModelAFactoryType = typeof ModelAInferred;
interface ModelAFactoryInterface extends ModelAFactoryType {}
export const ModelA: ModelAFactoryInterface = ModelAInferred;
export interface IModelAStore extends Instance<ModelAFactoryInterface> {}

const ModelBInferred = t.model({
a: ModelA
});

export type ModelBStoreType = Instance<typeof ModelB>;
export interface IModelBStore extends ModelBStoreType {}

// Hardcode the typing to reuse the ModelA type
type HardCodedModelType = IModelType<
{
a: typeof ModelA;
},
{},
_NotCustomized,
_NotCustomized
>;
type ModelBFactoryType = typeof ModelBInferred;
interface ModelBFactoryInterface extends ModelBFactoryType {}
export const ModelB: ModelBFactoryInterface = ModelBInferred;
export interface IModelBStore extends Instance<ModelBFactoryInterface> {}

export const ModelC: HardCodedModelType = t.model({
a: ModelA
const ModelCInferred = t.model({
// using that will create another declaration!
// b: ModelBInferred
b: ModelB
});
type ModelCFactoryType = typeof ModelCInferred;
interface ModelCFactoryInterface extends ModelCFactoryType {}
export const ModelC: ModelCFactoryInterface = ModelCInferred;
export interface IModelCStore extends Instance<ModelCFactoryInterface> {}

const ModelDInferred = t.compose(ModelC, ModelA);

export type ModelCStoreType = Instance<typeof ModelC>;
export interface IModelCStore extends ModelCStoreType {}
type ModelDFactoryType = typeof ModelDInferred;
interface ModelDFactoryInterface extends ModelDFactoryType {}
export const ModelD: ModelDFactoryInterface = ModelDInferred;
export interface IModelDStore extends Instance<ModelDFactoryInterface> {}
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"lib": ["dom", "es2015", "es2015.generator"],
"target": "es2015",
"lib": ["ESNext"],
"target": "ESNext",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"declaration": true,
"rootDir": "src",
"resolveJsonModule": false
"resolveJsonModule": false,
"emitDeclarationOnly": true,
"types": []
},
// "include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
Expand Down