Overmind & TypeScript Doubts

Some doubts I have:

Namespaces

This package should have a namespace called source. Each package should set its own namespace, and so it has to “export” it somehow. I don’t know how is the best way to do that.

Looking at the Overmind examples, it’s the root store who is giving names to each namespace.

Typing

When accessing other namespaces, for example, deriving a property using state from a different domain, it’s not clear to me where types come from. In the code below, imagine that selectedEntity is a derived prop (defined in the router package) that returns an object of type Entity (defined in the source package). I don’t know if implicit typing will work in this case or we need to import the external types explicitly.

// should external types be imported explicitly?
import { Entity } from '@frontity/wp-source';

export const state: State = {
  selectedItem: { type: 'post', id: 60 },
  selectedEntity: (state, rootState): Entity => {
    const { type, id } = state.selectedItem;
    return rootState.source.getEntity({ type, id });
  }
}

In that case, I don’t know how it would work either, especially considering that in-use packages are not known before runtime. Or is that going to be specified in the settings?

Maybe I’m thinking too much about this because of my little knowledge about TypeScript…

Yes, that’s it. It is explained with an example here: The packages export API

You’re absolutely right, we need to create packages for the APIs.

// router/state.js
import { Derive } from 'overmind';
import { Entity } from '@frontity/source-types';

type State {
  selectedItem: {
    type: string;
    id: number;
  }
  selectedEntity: Derive<State, Entity>
}

export const state: State = {
  selectedItem: { type: 'post', id: 60 },
  selectedEntity: (state, rootState): Entity => {
    const { type, id } = state.selectedItem;
    return rootState.source.getEntity({ type, id });
  }
}

I’ve opened a new topic to discuss it: The Frontity Types

I’ve tested Overmind’s namespaced and TypeScript locally and it works fine.

You can download and run this codesandbox and it works. I think the problem is with the overmind/config import.

Besides that, I’ve tested a combination of typed stores and non-typed stores and it works :slight_smile: