Is there a way to remove a property from an existing type without creating a new type without that property?
Contrived example:
type ArgType = {
name: string,
id: string,
count: number,
};
const RemoveName = ({name, ...rest}: ArgType) => rest;
Can I create a result type here from ArgType?
No, you can't do that at the moment
Actually, scratch that, you can do that:
type Foo = {
foo: string,
bar: string
}
const bar: $Diff<Foo, { foo: any }> = { bar: '123' };
$Diff doesn't behave properly in this use case, see https://github.com/facebook/flow/issues/2781
type Foo = {
foo: string,
bar: string
};
const bar: $Diff<Foo, { foo: any }> = { bar: undefined }; // no errors
Does it not work for polymorphic types?
````js
/* @flow */
function foo
foo(
{ name: '', age: 1 },
{ age: 1 },
{} // Should Error: 'name' prop is ommited
)
function bar bar( https://flowtype.org/try/#0PQKgBAAgZgNg9gdzCYAoVUCuA7AxgFwEs5swo44AeAFQBowBVegNQC4wASAEUKihvoMAfEIAU+dnTCZ2TMADd2zAJTt5cQgBMwAbwC+qMEeMnTRjBVGHdYbAEMAtgFN2Aclf07AcxdgAjGB6tNY6YN6+AUEhemDAwGAAygAWcJgw2gCiAE5ZcFlu9s6uYAAOuSVghADOYHAODoT4TpqoyuhYeEQkYABGdlmUbJw8fJShhb5V+FmE2F6ePuzYmA49TlmB9KHhSytrG3oioopgKmoa2vrWZjfmfVlWRvr0cWAAwnlZTgQwAJ5g2VyWSqrSAA
{}, // Correctly Errors
)
````
Most helpful comment
$Diffdoesn't behave properly in this use case, see https://github.com/facebook/flow/issues/2781