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

Typegen does not generate types correctly for types in modules #39

Open
rschyboll opened this issue Aug 9, 2022 · 0 comments
Open

Typegen does not generate types correctly for types in modules #39

rschyboll opened this issue Aug 9, 2022 · 0 comments

Comments

@rschyboll
Copy link

Environment

  • kea-typegen version: ^3.1.3
  • kea version: ^3.0.2
  • typescript version: ^4.7.4

This logic:

index.ts:

import { actions, kea, reducers } from 'kea';

import type { testLogicType } from './indexType';
import { TestModule } from './testModule';

export const testLogic = kea<testLogicType>([
  actions({
    testAction: true,
    testAction2: (input: TestModule.Type1) => ({ input }),
  }),
  reducers({
    testReducer: [{} as TestModule.Type2],
  }),
]);

testModule.ts:

export * as TestModule from './testTypes';

testTypes.ts:

export interface Type1 {}

export interface Type2 {}

Produces this type:

import type { Logic } from 'kea'

import type { TestModule, Type1 } from './testTypes'

export interface testLogicType extends Logic {
  actionCreators: {
    testAction: () => {
      type: 'test action (src.logic.core.test.index)';
      payload: {
        value: true;
      };
    };
    testAction2: (input: TestModule.Type1) => {
      type: 'test action2 (src.logic.core.test.index)';
      payload: {
        input: Type1;
      };
    };
  };
  actionKeys: {
    'test action (src.logic.core.test.index)': 'testAction';
    'test action2 (src.logic.core.test.index)': 'testAction2';
  };
  actionTypes: {
    testAction: 'test action (src.logic.core.test.index)';
    testAction2: 'test action2 (src.logic.core.test.index)';
  };
  actions: {
    testAction: () => void;
    testAction2: (input: TestModule.Type1) => void;
  };
  defaults: {
    testReducer: TestModule.Type2;
  };
  events: {};
  key: undefined;
  listeners: {};
  path: ['src', 'logic', 'core', 'test', 'index'];
  pathString: 'src.logic.core.test.index';
  props: Record<string, unknown>;
  reducer: (
    state: any,
    action: any,
    fullState: any,
  ) => {
    testReducer: TestModule.Type2;
  };
  reducers: {
    testReducer: (
      state: TestModule.Type2,
      action: any,
      fullState: any,
    ) => TestModule.Type2;
  };
  selector: (state: any) => {
    testReducer: TestModule.Type2;
  };
  selectors: {
    testReducer: (state: any, props?: any) => TestModule.Type2;
  };
  sharedListeners: {};
  values: {
    testReducer: TestModule.Type2;
  };
  _isKea: true;
  _isKeaWithKey: false;
}

It should instead:

import type { Logic } from 'kea'

import type { TestModule } from './testModule'

export interface testLogicType extends Logic {
  actionCreators: {
    testAction: () => {
      type: 'test action (src.logic.core.test.index)';
      payload: {
        value: true;
      };
    };
    testAction2: (input: TestModule.Type1) => {
      type: 'test action2 (src.logic.core.test.index)';
      payload: {
        input: TestModule.Type1;
      };
    };
  };
  actionKeys: {
    'test action (src.logic.core.test.index)': 'testAction';
    'test action2 (src.logic.core.test.index)': 'testAction2';
  };
  actionTypes: {
    testAction: 'test action (src.logic.core.test.index)';
    testAction2: 'test action2 (src.logic.core.test.index)';
  };
  actions: {
    testAction: () => void;
    testAction2: (input: TestModule.Type1) => void;
  };
  defaults: {
    testReducer: TestModule.Type2;
  };
  events: {};
  key: undefined;
  listeners: {};
  path: ['src', 'logic', 'core', 'test', 'index'];
  pathString: 'src.logic.core.test.index';
  props: Record<string, unknown>;
  reducer: (
    state: any,
    action: any,
    fullState: any,
  ) => {
    testReducer: TestModule.Type2;
  };
  reducers: {
    testReducer: (
      state: TestModule.Type2,
      action: any,
      fullState: any,
    ) => TestModule.Type2;
  };
  selector: (state: any) => {
    testReducer: TestModule.Type2;
  };
  selectors: {
    testReducer: (state: any, props?: any) => TestModule.Type2;
  };
  sharedListeners: {};
  values: {
    testReducer: TestModule.Type2;
  };
  _isKea: true;
  _isKeaWithKey: false;
}

Or this:

import type { Logic } from 'kea'

import type { Type1, Type2 } from './testTypes'

export interface testLogicType extends Logic {
  actionCreators: {
    testAction: () => {
      type: 'test action (src.logic.core.test.index)';
      payload: {
        value: true;
      };
    };
    testAction2: (input: Type1) => {
      type: 'test action2 (src.logic.core.test.index)';
      payload: {
        input: Type1;
      };
    };
  };
  actionKeys: {
    'test action (src.logic.core.test.index)': 'testAction';
    'test action2 (src.logic.core.test.index)': 'testAction2';
  };
  actionTypes: {
    testAction: 'test action (src.logic.core.test.index)';
    testAction2: 'test action2 (src.logic.core.test.index)';
  };
  actions: {
    testAction: () => void;
    testAction2: (input: Type1) => void;
  };
  defaults: {
    testReducer: Type2;
  };
  events: {};
  key: undefined;
  listeners: {};
  path: ['src', 'logic', 'core', 'test', 'index'];
  pathString: 'src.logic.core.test.index';
  props: Record<string, unknown>;
  reducer: (
    state: any,
    action: any,
    fullState: any,
  ) => {
    testReducer: Type2;
  };
  reducers: {
    testReducer: (
      state: Type2,
      action: any,
      fullState: any,
    ) => Type2;
  };
  selector: (state: any) => {
    testReducer: Type2;
  };
  selectors: {
    testReducer: (state: any, props?: any) => Type2;
  };
  sharedListeners: {};
  values: {
    testReducer: Type2;
  };
  _isKea: true;
  _isKeaWithKey: false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant