Computed Properties
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 215
- Avg merge
- 2h 9m
- Merged PRs (30d)
- 27
Description
The following section should be added to the language reference:
3.9 Computed Properties
You may use the following syntax to define computed properties.
Computed properties are syntactic sugar for getters and setters which themselves
are syntactic sugar for methods, therefore omitting either one is acceptable.
"Read block" must always return a value of the same type as the property.
Keyword new can be used inside the write block to access the incoming r-value
of the assignment (write) operation. new is always the same type as the type
of the property itself.
Both preflight and inflight computed properties are allowed.
Keyword var behind computed properties is not allowed.
inflight computed properties are also allowed.
// Wing Code:
struct Vec2 {
x: num;
y: num;
}
class Rect {
var size: Vec2;
var origin: Vec2;
center: Vec2 {
read {
let centerX = origin.x + (size.width / 2);
let centerY = origin.y + (size.height / 2);
return Vec2(x: centerX, y: centerY);
}
write {
origin.x = new.x - (size.width / 2);
origin.y = new.y - (size.height / 2);
}
};
inflight prop: num { /* ... */ }
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue does not name a documentation file; first locate the language reference and its section numbering, then compare nearby syntax sections for formatting and terminology. Add the Computed Properties section and verify that the Wing Code example and stated read, write, inflight, and var rules render correctly.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100