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

3.2.4 - TypeScript error on types.reference #994

Closed
4 tasks done
birkir opened this issue Aug 29, 2018 · 1 comment
Closed
4 tasks done

3.2.4 - TypeScript error on types.reference #994

birkir opened this issue Aug 29, 2018 · 1 comment
Assignees
Labels
bug Confirmed bug has PR A Pull Request to fix the issue is available Typescript Issue related to Typescript typings

Comments

@birkir
Copy link

birkir commented Aug 29, 2018

I have:

mobx-state-tree: 3.2.4
typescript: 3.0.1

  • I think something is not working as it should.
    • I've checked documentation and searched for existing issues
    • I've made sure your project is based on the latest MST version
    • Describe observed behavior

This is my case:

import { types } from 'mobx-state-tree';
import Cinemas from './Cinemas';

export const Cinema = types.model('Cinema', {
  id: types.identifier,
  name: types.maybe(types.string),
});

//               Here is a typescript error:   ↓
//                                             ↓
export const CinemaReference = types.reference(Cinema, {
  get(identifier: string) {
    return Cinemas.getOrLoadById(identifier) as typeof Cinema.Type || [];
  },
  set(value: typeof Cinema.Type) {
    return value.id;
  },
});

This is the error I get:

Argument of type 'IModelType<ModelPropertiesDeclarationToProperties<{ id: ISimpleType<string>; name: IComplexType<string | undefined, string | undefined, string | undefined> & OptionalProperty; }>, {}, ModelCreationType<...>, ModelSnapshotType<...>, ModelInstanceType<...>>' is not assignable to parameter of type 'IAnyModelType'.
  Types of property 'views' are incompatible.
    Type '<V extends Object>(fn: (self: ModelInstanceType<ModelPropertiesDeclarationToProperties<{ id: ISimpleType<string>; name: IComplexType<string | undefined, string | undefined, string | undefined> & OptionalProperty; }>, {}, ModelCreationType<...>, ModelSnapshotType<...>>) => V) => IModelType<...>' is not assignable to type '<V extends Object>(fn: (self: any) => V) => IModelType<any, any, ModelCreationType<any>, ModelSnapshotType<any>, any>'.
      Type 'IModelType<ModelPropertiesDeclarationToProperties<{ id: ISimpleType<string>; name: IComplexType<string | undefined, string | undefined, string | undefined> & OptionalProperty; }>, any, ModelCreationType<...>, ModelSnapshotType<...>, any>' is not assignable to type 'IModelType<any, any, ModelCreationType<any>, ModelSnapshotType<any>, any>'.
        Types of property 'preProcessSnapshot' are incompatible.
          Type '<S0 = ModelCreationType<ModelPropertiesDeclarationToProperties<{ id: ISimpleType<string>; name: IComplexType<string | undefined, string | undefined, string | undefined> & OptionalProperty; }>>>(fn: (snapshot: S0) => ModelCreationType<...>) => IModelType<...>' is not assignable to type '<S0 = ModelCreationType<any>>(fn: (snapshot: S0) => ModelCreationType<any>) => IModelType<any, any, S0, ModelSnapshotType<any>, any>'.
            Type 'IModelType<ModelPropertiesDeclarationToProperties<{ id: ISimpleType<string>; name: IComplexType<string | undefined, string | undefined, string | undefined> & OptionalProperty; }>, any, any, ModelSnapshotType<...>, any>' is not assignable to type 'IModelType<any, any, any, ModelSnapshotType<any>, any>'.
              Types of property 'postProcessSnapshot' are incompatible.
                Type '<S1 = ModelCreationType<ModelPropertiesDeclarationToProperties<{ id: ISimpleType<string>; name: IComplexType<string | undefined, string | undefined, string | undefined> & OptionalProperty; }>>>(fn: (snapshot: ModelSnapshotType<...>) => S1) => IModelType<...>' is not assignable to type '<S1 = ModelCreationType<any>>(fn: (snapshot: ModelSnapshotType<any>) => S1) => IModelType<any, any, S1, ModelSnapshotType<any>, any>'.
                  Types of parameters 'fn' and 'fn' are incompatible.
                    Types of parameters 'snapshot' and 'snapshot' are incompatible.
                      Type 'ModelSnapshotType<ModelPropertiesDeclarationToProperties<{ id: ISimpleType<string>; name: IComplexType<string | undefined, string | undefined, string | undefined> & OptionalProperty; }>>' is not assignable to type 'ModelSnapshotType<any>'.

Same goes for simple type.reference(Cinema)

@xaviergonz xaviergonz self-assigned this Aug 29, 2018
@xaviergonz xaviergonz added bug Confirmed bug Typescript Issue related to Typescript typings labels Aug 29, 2018
@xaviergonz
Copy link
Contributor

thanks! got a fix ready, will open a PR soon

@xaviergonz xaviergonz added the has PR A Pull Request to fix the issue is available label Aug 29, 2018
xaviergonz added a commit that referenced this issue Aug 29, 2018
fix for reference type issue in ts3 (#994)
@birkir birkir closed this as completed Aug 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug has PR A Pull Request to fix the issue is available Typescript Issue related to Typescript typings
Projects
None yet
Development

No branches or pull requests

2 participants