Skip to content

Comments with @~~ cause compiler errors when accessing member of Generic #16728

@Rokt33r

Description

@Rokt33r

TypeScript Version: 2.4.0

Code

  export interface PureAction <ACTION_TYPE> extends Redux.Action {
    readonly type: ACTION_TYPE
  }

  export interface PayloadAction <ACTION_TYPE, PAYLOAD> extends Redux.Action {
    readonly type: ACTION_TYPE
    readonly payload: PAYLOAD
  }

  export type Action = PureAction<any> | PayloadAction<any, any>

  export function createActionCreator <ACTION extends PayloadAction<ACTION['type'], ACTION['payload']>>(type: ACTION['type']): (payload: ACTION['payload']) => ACTION
  export function createActionCreator <ACTION extends PureAction<ACTION['type']>>(type: ACTION['type']): () => ACTION
  export function createActionCreator <ACTION extends PayloadAction<ACTION['type'], ACTION['payload']>>(type: ACTION['type']): (payload: ACTION['payload']) => ACTION {
    return (payload: any) => {
      if (payload == null) {
        return ({
          type,
        } as ACTION)
      }
      return ({
        type,
        payload,
      } as ACTION)
    }
  }

  type Reducer<STATE, ACTION> = (state: STATE, action: ACTION) => STATE
  /**
   *
   * test
   *
   * @export
   * @class MappedReducer
   * @template STATE
   * @template ACTION
   * @template Action
   * @template ACTION_TYPE
   * @template ACTION
   */
  export class MappedReducer<STATE, ACTION extends Action = Action, ACTION_TYPE extends ACTION['type'] = ACTION['type']> {
  }

Expected behavior:
No errors
Actual behavior:
[ts] Type '"type"' cannot be used to index type 'ACTION'. error occurred twice on Line 41:
export class MappedReducer<STATE, ACTION extends Action = Action, ACTION_TYPE extends ACTION['type']=ACTION['type']>

It works well if I delete all comment lines with @~~ like @export and @template.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions