Skip to main content
Module

x/rambda/path-spec.ts

Faster and smaller alternative to Ramda
Go to Latest
File
import {path} from 'rambda'
interface Input { a: number, b: { c: boolean, },}
describe('R.path', () => { it('without specified input type', () => { const input = {a: 1, b: {c: true}} const result = path<boolean>('a.b.c', input) const curriedResult = path<boolean>('a.b.c')(input) result // $ExpectType boolean | undefined curriedResult // $ExpectType boolean | undefined })
it('without specified output type', () => { const input = {a: 1, b: {c: true}} const result = path('a.b.c', input) result // $ExpectType unknown })
it('with string as path', () => { const input: Input = {a: 1, b: {c: true}} const resultA = path<boolean>('a.b.c', input) const resultB = path<boolean>('a.b.c')(input) resultA // $ExpectType boolean | undefined resultB // $ExpectType boolean | undefined }) it('with array as path', () => { const input: Input = {a: 1, b: {c: true}} const resultA = path<boolean>(['a', 'b', 'c'], input) const resultB = path<boolean>(['a', 'b', 'c'])(input) resultA // $ExpectType boolean | undefined resultB // $ExpectType boolean | undefined })})
describe('path with specified input', () => { it('with string as path', () => { const input: Input = {a: 1, b: {c: true}} // const wrongInput = { a: 1, b: true } // const resultA = path<Input, boolean>('a.b.c', wrongInput) const resultA = path<Input, boolean>('a.b.c', input) const resultB = path<Input, boolean>('a.b.c')(input) resultA // $ExpectType boolean | undefined resultB // $ExpectType boolean | undefined }) it('with array as path', () => { const input: Input = {a: 1, b: {c: true}} const resultA = path<Input, boolean>(['a', 'b', 'c'], input) const resultB = path<Input, boolean>(['a', 'b', 'c'])(input) resultA // $ExpectType boolean | undefined resultB // $ExpectType boolean | undefined })})