Skip to content

Conditional type on a lookup always never #29211

Closed
@atrauzzi

Description

@atrauzzi

TypeScript Version: 3.3.0-dev.20181229
Search Terms:

  • conditional types
  • lookup
  • broken

Code

export interface PassthroughProps<
    DataType extends {[key: string]: any},
    DataTypeKey extends string = Extract<keyof DataType, string>,
    IdentityCandidate extends DataTypeKey = DataType[IdentityCandidate] extends string 
        ? IdentityCandidate 
        : never,
> {
    identityProperty: IdentityCandidate;
    label: DataTypeKey | ((option: DataType) => string);
}

interface MyType {
    id: string;
    name: string;
    times: number;
}

const myprops: PassthroughProps<MyType> = {
    // ITEM 1
    identityProperty: "times",
    label: "id",
};

Expected behavior:

Item 1

I'm expecting identityProperty to be ( "id" | "name" ), not never.

Actual behavior:

Item 1

I'm getting this error:

Type 'string' is not assignable to type 'never'.ts(2322)

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