Skip to content
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

propIs #147

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 3 additions & 38 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2491,44 +2491,9 @@ declare namespace R {
/**
* Returns true if the specified object property is of the given type; false otherwise.
*/

// Record
propIs<T extends Function, K extends string, V, U extends Record<K,V>>(type: T, name: K, obj: U): obj is (U & Record<K, T>);
propIs<T extends Function, K extends string>(type: T, name: K): <V, U extends Record<K,V>>(obj: U) => obj is (U & Record<K, T>);
// propIs<T extends Function>(type: T): {
// <K extends string, V, U extends Record<K,V>>(name: K, obj: U): obj is (U & Record<K, T>);
// <K extends string>(name: K): <V, U extends Record<K,V>>(obj: U) => obj is (U & Record<K, T>);
// }
// propIs<T extends Function, K extends string, V, U extends Record<K,V>>: CurriedFunction3<T, K, U, V is (V & Record<K, T>)>; // obj is? name unavailable...

// inference, fails if name and object are supplied separately
propIs<T extends Function, V, K extends keyof V>(type: T, name: K, obj: V): obj is (V & Record<K, T>);
// propIs<T extends Function, V, K extends keyof V>(type: T, name: K): (obj: V) => obj is (V & Record<K, T>); // object info not available in time :(
// propIs<T extends Function>(type: T): {
// <V, K extends keyof V>(name: K, obj: V): obj is (V & Record<K, T>);
// <V, K extends keyof V>(name: K): (obj: V) => obj is (V & Record<K, T>); // object info not available in time :(
// }
// propIs<T extends Function, V, K extends keyof V>: CurriedFunction3<T, K, V, V is (V & Record<K, T>)>; // obj is? name unavailable...

// // curry-friendlier fallback
// // propIs(type: Function, name: Prop, obj: Struct<any>): boolean;
// propIs(type: Function, name: Prop): (obj: Struct<any>) => boolean;
// propIs(type: Function): CurriedFunction2<Prop, Struct<any>, boolean>;
// // propIs(type: Function): {
// // (name: Prop, obj: Struct<any>): boolean;
// // (name: Prop): (obj: Struct<any>) => boolean;
// // }
// // propIs: CurriedFunction3<Function, Prop, Struct<any>, boolean>;

// mixed:
propIs<T extends Function>(type: T): {
// record
<K extends string, V, U extends Record<K,V>>(name: K, obj: U): obj is (U & Record<K, T>);
<K extends string>(name: K): <V, U extends Record<K,V>>(obj: U) => obj is (U & Record<K, T>);
// keyof
<V, K extends keyof V>(name: K, obj: V): obj is (V & Record<K, T>);
// <V, K extends keyof V>(name: K): (obj: V) => obj is (V & Record<K, T>); // object info not available in time :(
};
propIs(type: Function, name: string, obj: Object): boolean;
propIs(type: Function, name: string): CurriedFunction1<Object, boolean>;
propIs(type: Function): CurriedFunction2<string, Object, boolean>;

/**
* If the given, non-null object has an own property with the specified name, returns the value of that property.
Expand Down
2 changes: 1 addition & 1 deletion tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class F2 {
R.propIs(Number)('x', {x: 1, y: 2}); // => true // $ExpectType boolean
R.propIs(Number)('x')({x: 1, y: 2}); // => true // $ExpectType boolean
R.propIs(Number, 'x', {x: 'foo'}); // => false // $ExpectType boolean
R.propIs(Number, 'x', {}); // => false // $ExpectError Argument of type 'x' is not assignable to parameter of type 'never'.`, because 'x' is not in `{}`.
R.propIs(Number, 'x', {}); // => false // $ExpectType boolean
});

// type
Expand Down