IssueRaiser

Suggestion: Units of measure

This feature request is similar to [units of measure in F#](http://msdn.microsoft.com/en-us/library/dd233243.aspx). For example: ``` typescript const metres = 125<m>; const seconds = 2<s>; let speed: number<m/s>; speed = metres / seconds; // valid speed = metres / seconds / 10<s>; // error -- cannot convert m/s**2 to m/s ``` (Moved from [work item 1715 on Codeplex](https://typescript.codeplex.com/workitem/1715).) # Proposal **Last Updated:** 2016-06-09 **Copied from:** https://github.com/dsherret/Units-of-Measure-Proposal-for-TypeScript --- ## Overview Units of measure is a useful [F# feature](http://msdn.microsoft.com/en-us/library/dd233243.aspx) that provides the optional ability to create tighter constraints on numbers. TypeScript could benefit from a similar feature that would add **zero runtime overhead**, increase type constraints, and help decrease programmer error when doing mathematical calculations that involve units. The feature should prefer explicity. ## Defining Units of Measure Units of measure should probably use syntax similar to type aliases (#957). More discussion is needed on this, but for the purpose of this document it will use the following syntax: ``` typescript type measure <name> [ = measure expression ]; ``` The optional measure expression part can be used to define a new measures in terms of previously defined measures. ### Example Definitions ``` typescript type measure m; type measure s; type measure a = m / s**2; ``` Uni

Posted by dsherret on Aug 5, 2014, 9:26 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.9,000 issues0 comments

github (Software)

Suggestion: Units of measure

dsherretAug 5, 2014, 9:26 PM

This feature request is similar to [units of measure in F#](http://msdn.microsoft.com/en-us/library/dd233243.aspx). For example: ``` typescript const metres = 125<m>; const seconds = 2<s>; let speed: number<m/s>; speed = metres / seconds; // valid speed = metres / seconds / 10<s>; // error -- cannot convert m/s**2 to m/s ``` (Moved from [work item 1715 on Codeplex](https://typescript.codeplex.com/workitem/1715).) # Proposal **Last Updated:** 2016-06-09 **Copied from:** https://github.com/dsherret/Units-of-Measure-Proposal-for-TypeScript --- ## Overview Units of measure is a useful [F# feature](http://msdn.microsoft.com/en-us/library/dd233243.aspx) that provides the optional ability to create tighter constraints on numbers. TypeScript could benefit from a similar feature that would add **zero runtime overhead**, increase type constraints, and help decrease programmer error when doing mathematical calculations that involve units. The feature should prefer explicity. ## Defining Units of Measure Units of measure should probably use syntax similar to type aliases (#957). More discussion is needed on this, but for the purpose of this document it will use the following syntax: ``` typescript type measure <name> [ = measure expression ]; ``` The optional measure expression part can be used to define a new measures in terms of previously defined measures. ### Example Definitions ``` typescript type measure m; type measure s; type measure a = m / s**2; ``` Uni

Comments (0)

No comments yet. Start the discussion.

Comment on this issue