JannicBeck / undox

⎌ Redux Implementation of Undo/Redo based on storing actions instead of states.
MIT License
24 stars 5 forks source link

tsc fail to compile project with undox #38

Closed Buggytheclown closed 3 years ago

Buggytheclown commented 3 years ago

We have type check on CI that start to fail after we add undox to the project. I think undox should be compiled properly to include d.ts without .ts files

Step to reproduce:

Errors:

All imports in import declaration are unused.

  1 import {
    ~~~~~~~~
  2   UndoxAction,
    ~~~~~~~~~~~~~~
... 
  4   UndoAction
    ~~~~~~~~~~~~
  5 } from '../undox.action'
    ~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/undox/src/undox.reducer.ts:27:51 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
    Argument of type 'T | T[]' is not assignable to parameter of type 'ConcatArray<never>'.
      Type 'T' is not assignable to type 'ConcatArray<never>'.
  Overload 2 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
    Argument of type 'T | T[]' is not assignable to parameter of type 'ConcatArray<never>'.
      Type 'T' is not assignable to type 'ConcatArray<never>'.

27 const flatten = <T> (x: (T | T[])[]) => [].concat(...x) as T[]
                                                     ~~~~

node_modules/undox/src/undox.reducer.ts:30:69 - error TS2322: Type 'S | undefined' is not assignable to type 'S'.
  'S' could be instantiated with an arbitrary type which could be unrelated to 'S | undefined'.
    Type 'undefined' is not assignable to type 'S'.
      'S' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.

30 const calculateState: CalculateState = (reducer, actions, state) => flatten(actions).reduce(reducer, state)
                                                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/undox/src/interfaces/internal.ts:15:18
    15 export interface CalculateState {
                        ~~~~~~~~~~~~~~
    The expected type comes from the return type of this signature.

node_modules/undox/src/undox.reducer.ts:72:50 - error TS6133: 'history' is declared but its value is never read.

72 const doNPastStatesExist   : DoNStatesExist = ({ history, index }, nStates) => index >= nStates
                                                    ~~~~~~~

node_modules/undox/src/undox.reducer.ts:76:7 - error TS2322: Type '<S, A extends Action<any>>(state: UndoxState<S, A>, action: GroupAction<A>, reducer: Reducer<S, A>, comparator: Comparator<S>) => UndoxState<...> | { ...; }' is not assignable to type 'Group'.
  Type 'UndoxState<S, A> | { history: (A | A[] | undefined)[]; index: number; present: Readonly<S>; }' is not assignable to type 'UndoxState<S, A>'.
    Type '{ history: (A | A[] | undefined)[]; index: number; present: Readonly<S>; }' is not assignable to type 'UndoxState<S, A>'.
      Types of property 'history' are incompatible.
        Type '(A | A[] | undefined)[]' is not assignable to type 'readonly (A | A[])[]'.
          Type 'A | A[] | undefined' is not assignable to type 'A | A[]'.
            Type 'undefined' is not assignable to type 'A | A[]'.

76 const group: Group = (state, action, reducer, comparator) => {
         ~~~~~

node_modules/undox/src/undox.reducer.ts:79:21 - error TS2532: Object is possibly 'undefined'.

79   const nextState = action.payload.reduce(reducer, state.present)
                       ~~~~~~~~~~~~~~

Found 6 errors.
JannicBeck commented 3 years ago

I will look into it on the weekend and create a release together with limit feature, I'm currently pretty busy at work.

JannicBeck commented 3 years ago

@Buggytheclown Just released version 1.4.0 with limit and tsc compile fix. I will add the limit feature to the documentation but for now test files should be self explanatory :)