Skip to content
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

Issues with Typescript 3.5.1 release #1307

Closed
jrmyio opened this issue Jun 4, 2019 · 24 comments · Fixed by #1346
Closed

Issues with Typescript 3.5.1 release #1307

jrmyio opened this issue Jun 4, 2019 · 24 comments · Fixed by #1346
Labels
bug Confirmed bug has PR A Pull Request to fix the issue is available require('@mweststrate') @mweststrate input is required! Typescript Issue related to Typescript typings

Comments

@jrmyio
Copy link
Contributor

jrmyio commented Jun 4, 2019

Typescript 3.5.1 just got released. After upgrading from typescript@3.5.0-dev.20190512 the following no longer seems to be working:

import { types, IAnyType } from "mobx-state-tree";

export const createCustomType = <ICustomType extends IAnyType>({
  CustomType
}: {
  CustomType: ICustomType;
}) => {
  return types
    .model("Example", {
      someProp: types.boolean,
      someType: CustomType
    })
    .views(self => ({
      get isSomePropTrue(): boolean {
        return self.someProp;
      }
    }));
};

Here is the complete error:

Property 'someProp' does not exist on type 'STNValue<ModelInstanceTypeProps<ModelPropertiesDeclarationToProperties<{ someProp: ISimpleType<boolean>; someType: ICustomType; }>>, IModelType<ModelPropertiesDeclarationToProperties<{ someProp: ISimpleType<boolean>; someType: ICustomType; }>, {}, _NotCustomized, _NotCustomized>>'.
  Property 'someProp' does not exist on type 'Exclude<ModelInstanceTypeProps<ModelPropertiesDeclarationToProperties<{ someProp: ISimpleType<boolean>; someType: ICustomType; }>>, object>'.ts(2339)

Are the typings of MST compatible with TS 3.5.1?

When hovering over self of .views(self => ({. In TS 3.4.3 it was:

(parameter) self: ModelInstanceTypeProps<ModelPropertiesDeclarationToProperties<{
    someProp: ISimpleType<boolean>;
    someType: ICustomType;
}>> & IStateTreeNode<IModelType<ModelPropertiesDeclarationToProperties<{
    someProp: ISimpleType<boolean>;
    someType: ICustomType;
}>, {}, _NotCustomized, _NotCustomized>>

While in TS 3.5.1 self of .views(self => ({ seems to be:

(parameter) self: STNValue<ModelInstanceTypeProps<ModelPropertiesDeclarationToProperties<{
    someProp: ISimpleType<boolean>;
    someType: ICustomType;
}>>, IModelType<ModelPropertiesDeclarationToProperties<{
    someProp: ISimpleType<boolean>;
    someType: ICustomType;
}>, {}, _NotCustomized, _NotCustomized>>

I tracked down that thing started breaking since typescript@3.5.0-dev.20190514. typescript@3.5.0-dev.20190512 was still fine.

@danielkcz
Copy link
Contributor

Yea looks like that 3.5.1 has broken more things. Specifically, I noticed when this sits in the same file as a model definition, the model turns out "any". It was working fine with TS 3.4. Moving that interface to different file works.

const RootModel = types.model('Root', {}) // == any

export interface TRootModel extends Instance<typeof RootModel> {}

This will need some deep understanding of TypeScript changes which I am lacking. Linking release notes for a reference...

https://devblogs.microsoft.com/typescript/announcing-typescript-3-5/

@danielkcz danielkcz added bug Confirmed bug require('@mweststrate') @mweststrate input is required! Typescript Issue related to Typescript typings labels Jun 8, 2019
@danielkcz danielkcz changed the title My factory just broke with Typescript 3.5.1 release Issues with Typescript 3.5.1 release Jun 8, 2019
@danielkcz danielkcz pinned this issue Jun 8, 2019
@xaviergonz
Copy link
Contributor

@FredyC that particular case (an empty model) might be related with this
#1269

Does it do the same if the model has at least one required property?

@saboteurspk
Copy link

Probably has to do something with mobx-state-tree changes as well.
Version "mobx-state-tree": "3.10.2" works fine for me. If I upgrade to latest, the problems with .views (as described above) appears.

@danielkcz
Copy link
Contributor

danielkcz commented Jun 26, 2019

I finally got to preparing a proper reproduction of the issue I've mentioned above. Sadly, CodeSandbox is quirky as usual and actually works for some weird reason. Here goes the repo...

https://github.com/FredyC/mobx-state-tree-ts3.5

After some initial digging, it seems that the main culprit lies about the BaseModel. The TS 3.5 got more strict or what and doesn't like such an approach. Unfortunately, I haven't found any TS option that could be causing it.

@danielkcz
Copy link
Contributor

danielkcz commented Jun 27, 2019

Well, I got an answer at SO that has nudged me the right way, but something is definitely wonky here.

I am sorry, but I have to ping you here @mweststrate as it basically makes MST unusable with TS 3.5, so I wonder if have some insight here. The MST typing is really complex and I have no idea where to start looking.

@kresli
Copy link

kresli commented Jun 28, 2019

just created a new project and even very simple example doesn't work 😢
image

@jrmyio
Copy link
Contributor Author

jrmyio commented Jul 11, 2019

It's been 13 days since the last activity in this issue...
Where to go from here @mweststrate ?

Considering the complexity of MST's typing I don't think many people are capable to resolve this issue.

@mweststrate
Copy link
Member

I am currently having holiday, so it will take a few weeks before I can dive into this. @xaviergonz might have ideas, or otherwise you'll have to stick to older TS version for a bit. I might not be able to take a look before half august

@mweststrate
Copy link
Member

Ok, had a few hours to spare and upgraded TS, see #1339. As far as I can see no new problems where introuced. I tried reproducing the issue reported by @kresli, but it doesn't occur in our test. So please verify your compiler settings are the same (also added those to the docs now):

{
    "strict": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "noImplicitAny": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitReturns": true,
    "noImplicitThis": true
}

Will also verify the original issue reported by @ConneXNL

@mweststrate
Copy link
Member

Side note: for TS specific issues I typically have some problem with codesandbox, as tsconfig doesn't seem to be properly picked up occasionally, and stackblitz seems to do a better job here...

@mweststrate
Copy link
Member

@ConneXNL the definition of ICustomExample is incomplete, as it should be <ICustomType extends ModelPrimitive | IAnyType>. I think somehow TS didn't pick up on this before, where it should have. Anyway, ModelPrimitive is not exposed atm from the library, but #1307 fixes that as well, which should fix this issue.

@mweststrate mweststrate added the has PR A Pull Request to fix the issue is available label Jul 13, 2019
@danielkcz
Copy link
Contributor

@mweststrate Any idea about my issue? https://github.com/FredyC/mobx-state-tree-ts3.5

Btw, strict option should be enough alone as it enables all others.

@mweststrate
Copy link
Member

mweststrate commented Jul 13, 2019 via email

@danielkcz
Copy link
Contributor

danielkcz commented Jul 13, 2019

@mweststrate Sorry, I kinda hijacked it here as it seemed a good idea to consolidate all TS 3.5 issues here 🙈

Either way, the strangest thing is that circular reference you are talking about worked with 3.4. I wouldn't bother otherwise.

@mweststrate
Copy link
Member

mweststrate commented Jul 13, 2019 via email

@danielkcz danielkcz unpinned this issue Jul 13, 2019
mweststrate added a commit that referenced this issue Jul 15, 2019
Updated typescript to 3.5.3, to verify #1307
@jrmyio
Copy link
Contributor Author

jrmyio commented Jul 15, 2019

@mweststrate Not sure if you meant do this, but you uncommented
https://github.com/mobxjs/mobx-state-tree/blob/master/packages/mobx-state-tree/__tests__/core/type-system.test.ts#L1039

So yes, then the error goes away....

@mweststrate
Copy link
Member

mweststrate commented Jul 15, 2019 via email

@jrmyio
Copy link
Contributor Author

jrmyio commented Jul 15, 2019

@mweststrate Hmm, for me it does not. I also tried to clone mst but I am getting the same error in the tests (tried both typescript 3.5.2 and 3.5.3):

image

@mweststrate
Copy link
Member

mweststrate commented Jul 16, 2019 via email

@kresli
Copy link

kresli commented Jul 17, 2019

@mweststrate adding "strictNullChecks": true solve basic types.optional issue for me. Stupid me, I forgot to check tsconfig. strict: true alone is not enough.

@danielkcz
Copy link
Contributor

@kresli That sounds strange, here is the snapshot from offic. docs...

image

@kresli
Copy link

kresli commented Jul 17, 2019

@FredyC yes you right, I double checked it and either strict: true or strictNullCheck: true works.

@mweststrate
Copy link
Member

Released as 3.14.1

@lock
Copy link

lock bot commented Jan 14, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug has PR A Pull Request to fix the issue is available require('@mweststrate') @mweststrate input is required! Typescript Issue related to Typescript typings
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants