Merge pull request #21486 from nenadalm/ramda

[ramda]: Fix `prop` type
This commit is contained in:
Bowden Kelly
2017-12-06 10:52:35 -08:00
committed by GitHub
2 changed files with 11 additions and 2 deletions

View File

@@ -1454,9 +1454,8 @@ declare namespace R {
/**
* Returns a function that when supplied an object returns the indicated property of that object, if it exists.
* Note: TS1.9 # replace any by dictionary
*/
prop<P extends string, T>(p: P, obj: Record<P, T>): T;
prop<P extends keyof T, T>(p: P, obj: T): T[P];
prop<P extends string>(p: P): <T>(obj: Record<P, T>) => T;
/**

View File

@@ -1535,6 +1535,16 @@ class Rectangle {
() => {
const x: number = R.prop("x", {x: 100}); // => 100
const obj = {
str: 'string',
num: 5,
};
const strVal: string = R.prop('str', obj); // => 'string'
const numVal: number = R.prop('num', obj); // => 5
const strValCur: string = R.prop('str')(obj); // => 'string'
const numValCur: number = R.prop('num')(obj); // => 5
};
() => {