-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ramda Omit should return Partial<T> instead of T #183
Comments
Yeah, fair enough. That said, at this point I did figure out how to do type level omit now. Put it in a gist but currently on phone. |
For reference, my progress on typing it further (see here): export type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;
// needs TS 2.5
export type Diff<T extends string, U extends string> =
({[P in T]: P } &
{ [P in U]: never } &
{ [k: string]: never })[T];
// alternative for older TS:
export type UnionDiff_<Big extends string, Small extends string> =
{[K in Big]: { 1: Union2Keys<Big>[K], 0: never }[Not<UnionHasKey<Small, K>>]}//[Big];
export type UnionDiff<
Big extends string,
Small extends string,
Step extends UnionDiff_<Big, Small> = UnionDiff_<Big, Small>
> = Step[Big]; I'd like to retype the whole library more accurately with things like this, but still got a few obstacles and need to test a lot more whether things wouldn't break down with less granular types. Until then, feel free to send a PR to make it use |
Currently my hack is
the T generic is used for the OUTPUT I was looking for. When using Also in I also tried with this one
By specifing type of Input and Output object, since I use VSCODE it helps me with tips on which key I can input on and which key value pairs I get back from the result. I only use this one if I have a huge lists of object keys in my third party library and want to avoid typo. I think currently it's impossible to get difference between object in typescript. I have checked every default definitions library from typescript and core-js itself. There is no single implementation of difference between two stuffs. |
We used to have typings like this, but I think they don't add much value: it seems little different from just explicitly casting the result like
Did you check my link? You're not likely to find it used anywhere yet cuz we just only recently figured out how one might be able to do it. |
Yes, I checked your link, I also try all of the type definition in your gist link but nothing works |
I can't get it to work as a function yet either, just like const keys: ['a', 'b'] = ['a', 'b'];
const obj: { a: 1, b: 2, c: 3 } = { a: 1, b: 2, c: 3 };
declare function omit<T, Keys extends string[]>(names: Keys, obj: T): Omit<T, TupleToUnion<Keys>>;
const omitTest = omit(keys, obj);
// expect {c:3}, get Pick<{ a: 1; b: 2; c: 3; }, "a" | "b" | "c">
declare function omit2<Keys extends string[]>(names: Keys): TupleToUnion<Keys>;
const omitTest2 = omit2(keys);
// expect 'a'|'b', got never
type abc1 = TupleToUnion<['a', 'b']>;
// 'a'|'b'
type abc2 = TupleToUnion<string[]>;
// gives never, did omitTest2 have it turn into string[] too?
declare function omit3<Keys extends string[]>(names: Keys): Keys;
const omitTest3 = omit3(keys);
// ["a", "b"] as expected, no info lost here... weird. So yeah, the jump to functions is one thing I'm still having trouble with... |
Filed as bug here now. |
Actually works now on master. Guess there is hope! |
There are few type issue on Ramda declaration
for example:
should be
or maybe a
Pict<T1, T2>
omitting means removing parts of object specified in the second argument and return new object without the specified lists of key, so it should return Partial instead of T since it will returning only some part of the object key value
The text was updated successfully, but these errors were encountered: