Skip to content

Exclude doesn't work with extended generics #24791

Closed
@niba

Description

@niba

TypeScript Version: 2.9.1, 3.0.0-dev.20180608

Search Terms:
keyof generics extend exclude
Code

type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;

interface RequiredFields {
    requiredField: string;
    requiredField2: string;
}

// works
interface MyInterface extends RequiredFields { }

type ExcludeTest = Exclude<MyInterface, "">; 
type Fields = Omit<MyInterface, "">;
const test = (props: Fields) => {
    const { requiredField } = props;
}

// doesnt work

const generator = <T extends RequiredFields>() => {
    type ExcludeTest = Exclude<T, "">; // wrong 
    type PickTest = Pick<T, "requiredField">;

    type Fields = Omit<T, "">;
    const tmp = (props: Fields) => {
        const {  } = props; // requiredField doesnt exist
    }
    return tmp;
}

Expected behavior:

Props in generator should have RequiredFields fields.

Actual behavior:

Props are empty.

Playground Link: Link
Related Issues:
#21941 #21862.
The issues are closed but the bug is still here

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions