Feature Suggestion: Filtering types by literal property comparison
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Suppose I have the following types:
```javascript
type Test = {
testType: 'single'|'set'
}
type TestSet = Test & {
testType: 'set',
setOnlyProperty: string
}
type TestSingle = Test & {
testType: 'single',
singleOnlyProperty: string
}
```
It would be very useful to be able to say,
```javascript
var test: Test = ...;
if(testType === 'set') {
console.log(test.setOnlyProperty);
} else {
console.log(test.singleOnlyProperty);
}
```
I'd think this would be doable, but I'm not a type-system expert. It also occurs to me now that once the ES pattern-matching syntax comes out this kind of thing would be even more useful, and possibly easier to implement.
Contributor guide
Assessment
This issue has not been assessed yet.