-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
TypeScript Version: 4.0.5, 4.1-beta, 4.2.0-dev
Search Terms: TS2345 conditional generic
Code: (Playground Link)
export const DatePicker = <IsClearable extends boolean>({
value, onChange, isClearable
}: {
value: string | undefined
onChange: (
value: IsClearable extends true ? string | undefined : string,
) => void;
isClearable?: IsClearable;
}) => (
<>
<div>{value ?? "Choose"}</div>
// In an ideal world this one would works, but that's not the biggest issue
{value && isClearable && <button onClick={() => onChange(undefined!)}>Clear</button>}
// This one seems more like a bug
<input type="date" onChange={e => onChange(e.target.value)} />
</>
);
Expected behavior: No error
Actual behavior: Argument of type 'string' is not assignable to parameter of type 'IsClearable extends true ? string | undefined : string'
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created