You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
src/a.ts(3,43): error TS2344: Type '({ [P in T]: P; } & { [P in U]: never; } & { [x: string]: never; })[keyof T]' does not satisfy the constraint 'keyof T'.
Type '({ [P in T]: P; } & { [P in U]: never; })[keyof T]' is not assignable to type 'keyof T'.
These types were taken from #12215 (comment) so are present in a few DefinitelyTyped packages.
There was no error in typescript@2.7.0-dev.20180110. Error discovered in recompose (among others) on DefinitelyTyped.
Nathan Shively-Sanders (@sandersn) I believe that the part of Diff you said is not sound is what makes it actually work as a difference type hack. I don't quite understand the trick myself, but it happens to work and is very useful 🤔
Daniel Rosenwasser (@DanielRosenwasser) also pointed out that taken as a whole, ({ [P in T]: P } & { [P in U]: never})[T] is sound, because the intersection is gauranteed to have at least the properties of T. However, the current algorithm just iterates through the members of the intersection for assignability.
In any case, my initial diagnosis is wrong. The reason these types fail is that the constraint of ({ [P in T]: P } & { [P in K]: never} & { [s:string]: never })[keyof T] must be assignable to keyof T in order to satisfy K extends keyof T in the second parameter of Omit. Before #17912 the constraint was incorrectly any, which is of course assignable to anything. After #17912, the constraint was incorrectly not present, because of a transform that removes string-index-only types from intersections.
The fix in #21156 avoids this transform, so the constraint is never, which is assignable to keyof T.
Has this been released already because Omit doesn't seem to work in 2.7.2 with optional properties.
I have a base interface that comes from a library, which defines lots of optional component properties and my component is expected to allow defining all those properties except a couple. I was trying to use the oh so popular implementation of Omit but it seems to be completely ignoring optional types.
Then when I use my component that implements the interface as follows - class MyComponent extends React.Component<MyComponentProps> {} - I am not being allowed to define any of the original component properties apart from the custom1:
Property 'optional1' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<MyComponent> & Readonly<{ children?: ReactNode;...'
Reacted by Vladislav Melnikov, Alec Merdler, Vladimir Zotov and Vladimir Rindevich
Activity
sandersn commentedon Jan 11, 2018
Briefly, this error is correct. The second half of
Diffis not sound:Consider
T={ a, b }, K='a'. Then{ [P in K]: any }[keyof T]is not defined whenkeyof T='b'.The question is how to make these libraries work again.
sandersn commentedon Jan 12, 2018
Fix is up at #21156
Jessidhia commentedon Jan 12, 2018
Nathan Shively-Sanders (@sandersn) I believe that the part of
Diffyou said is not sound is what makes it actually work as a difference type hack. I don't quite understand the trick myself, but it happens to work and is very useful 🤔sandersn commentedon Jan 12, 2018
Daniel Rosenwasser (@DanielRosenwasser) also pointed out that taken as a whole,
({ [P in T]: P } & { [P in U]: never})[T]is sound, because the intersection is gauranteed to have at least the properties of T. However, the current algorithm just iterates through the members of the intersection for assignability.In any case, my initial diagnosis is wrong. The reason these types fail is that the constraint of
({ [P in T]: P } & { [P in K]: never} & { [s:string]: never })[keyof T]must be assignable tokeyof Tin order to satisfyK extends keyof Tin the second parameter ofOmit. Before #17912 the constraint was incorrectlyany, which is of course assignable to anything. After #17912, the constraint was incorrectly not present, because of a transform that removes string-index-only types from intersections.The fix in #21156 avoids this transform, so the constraint is
never, which is assignable tokeyof T.Fix EuiContextMenu types
codeaid commentedon Mar 11, 2018
Has this been released already because Omit doesn't seem to work in 2.7.2 with optional properties.
I have a base interface that comes from a library, which defines lots of optional component properties and my component is expected to allow defining all those properties except a couple. I was trying to use the oh so popular implementation of Omit but it seems to be completely ignoring optional types.
Consider this scenario:
Then when I use my component that implements the interface as follows -
class MyComponent extends React.Component<MyComponentProps> {}- I am not being allowed to define any of the original component properties apart from thecustom1: