Skip to content

Type 'P' is not assignable to type 'boolean'. #31151

@SalathielGenese

Description

@SalathielGenese

I am actively looking suggestion to better describe this issue. We discussed it over three days now in the Gitter channel. Most recent reference at the time of writing these lines is ☝️ April 28, 2019 10:26 PM

TypeScript Version: 3.5.4

Search Terms: Type 'T' is not assignable to type '

Code

// import { Action } from 'redux';
type Action<T> = { type: T }

const actions: ActionMap<Type> = {
    setIsPublic: ( payload: boolean ) => ({ type: 'z' as Type, payload }),
//  ^^^^^^^^^^^
};

interface ActionMap<T extends string>
{
    [ name: string ]: <P>( payload: P ) => Action<T> & { payload: P };
}

enum Type { SET_PUBLIC = 'SET_PUBLIC', SET_PRIVATE = 'SET_PRIVATE' };

Expected behavior: No error

Actual behavior: Error at setIsPublic

Type '(payload: boolean) => { type: Type; payload: boolean; }' is not assignable to type '<P>(payload: P) => Action<Type> & { payload: P; }'.
  Types of parameters 'payload' and 'payload' are incompatible.
    Type 'P' is not assignable to type 'boolean'.

Playground Link: Follow me

Related Issues: No

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions