Skip to content

Proposal - Nested property access notation for types #10693

Description

This strawman proposal aims to bring type-safety to a common "nested properties access" pattern in JavaScript libraries.

A common eww-case

Consider the following snippets that use RxJS & Immutable.js: they select / update nested properties using sequences of literal property names, and are currently impossible to model in a type-safe way (making their use perillous / brittle at best):

const obs = Observable.of({a: {b: {c: 1}}});
obs.pluck('a', 'b', 'c') // Observable<number>

var nested1 = Immutable.fromJS({a: {b: {c: 1}}});
nested1.getIn(['a', 'b', 'c']) // number
var nested2 = nested1.updateIn(['a', 'b', 'd'], value => value + 1);

To sleep better at night, I'd like to be able to declare something like:

interface Observable<T> {
  pluck<Props extends const string[]>(...names: