ericelliott / ericelliott/rtype

Context dependent types

Open
#98 11 comments 0 reactions 0 assignees View on GitHub
proposal
Dominant language
JavaScript
Stars
1.1k
Forks
38
PR merge metrics
No merged PRs in 30d

Description

See issue #97 for some prior discussion.

Consider a simple nested object which groups expense per hobby per person :

```
{
joe: {
skating: {time: 1000, money: 300},
cooking: {time: 9999, money: 999}
},
emily: {
running: {time: 300, money: 0}
}
}
```

We can consider these as 3 separate objects (unusual key definition comes from a derivation of a solution proposed in issue #97) :

```
interface Expense {
time: Number, money: Number
}
interface ExpBy_Hobby {
String: Expense
}
interface ExpBy_Hobby_Person {
String: ExpBy_Hobby
}
```

This describes the composition of the outer object for us. But we are missing some context otherwise provided by predefined key names.

The Expense object gains context for it's Number values by their well named counterpart keys. Non-predefined keys such as those seen on the ExpBy_Hobby & ExpBy_Hobby_Person objects can't provide such context.

I believe the documentation aspect of this specification would benefit greatly from the inclusion of a key definition syntax. Something like the following :

```
interface ExpBy_Hobby {
(hobby : String): Expense
}
def hobby {
desc: "The name of a hobby",
source: {type: "database", location: "hobby.id"}
}
```

For objects which gain all their meaning from the data they contain rather than their specific structure, and are otherwise difficult to discern, this is an essential documentation requirement for processes which might polymorphically handle them together.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.