Skip to content

Type constraint is not respected when using nested generic types B<A> where A is a property type of B  #27427

Closed
@timargra

Description

@timargra

TypeScript Version: 3.2.0-dev.20180927

Code

export interface DocumentRef<T extends string> {
    id: number;
    type: T;
}

export type PartialDocument<R extends DocumentRef<R['type']> = R> = {
    [P in keyof R]?: R[P];
} & DocumentRef<R['type']>;

Expected behavior:

const test: PartialDocument = {id: 1, type: 1} // Error: Type 'number' is not assignable to type 'string'

Actual behavior:

const test: PartialDocument = {id: 1, type: 1} // No error, type of test.type is always 'unknown'

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions