Skip to content

Commit 00967f4

Browse files
committed
Update README.md
1 parent 15bcfa4 commit 00967f4

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ Units of Measure: Proposal for TypeScript
33

44
[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)
55

6-
-- Unfinished --
7-
86
## Overview
97

108
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 floating point and signed integer values.
119

12-
TypeScript could benefit from a similar Units of Measure feature and expand to include tiny type support for `string`, `boolean`, and `date` objects. Such a feature would add zero runtime overhead, increase type constraints, and help decrease programmer error.
10+
TypeScript could benefit from a similar units of measure feature and expand to include tiny type support for `string`, `boolean`, and `date` objects. Such a feature would add zero runtime overhead, increase type constraints, and help decrease programmer error.
1311

1412
## Defining Type Annotations
1513

@@ -19,6 +17,8 @@ Type annotations are defined similarly to ambient types:
1917
declare type <unit-name> [ = measure ];
2018
```
2119

20+
The optional measure part can be used to define a new type in terms of previously defined types. Note that this composite type cannot be used with non-`number` types.
21+
2222
**Examples:**
2323

2424
```typescript
@@ -28,7 +28,7 @@ declare type a = m/s^2;
2828
declare type email;
2929
```
3030

31-
Note: The caret symbol is not used as the bitwise XOR operator, but as an exponent. In this case, `m/s^2` is equivalent to `m/s/s`.
31+
Note: The caret symbol does not denote a bitwise XOR operator, but rather an exponent. In this case, `m/s^2` is equivalent to `m/s/s`.
3232

3333
## Use with Number
3434

@@ -66,14 +66,14 @@ sendEmail(myEmail, "Hello!"); // valid
6666
sendEmail("some string", "Hello!"); // compile error -- Cannot convert string to string<email>
6767
```
6868

69-
Take note that the following is invalid with non-number types:
69+
However, the following is invalid with non-number types:
7070

7171
```typescript
7272
declare type m;
7373
declare type s;
7474
declare type a = m/s^2;
7575

76-
var myString : string<a>; // compile error -- Cannot use a compound unit annotation for non-number types
76+
var myString : string<a>; // compile error -- Cannot use composite types with non-number types
7777
```
7878

7979
## Additional Cases
@@ -86,7 +86,7 @@ declare type flag;
8686

8787
var num = new Number<m>(),
8888
str = new String<email>(),
89-
date = new String<startDate>(),
89+
date = new Date<startDate>(),
9090
b = new Boolean<flag>();
9191
```
9292

@@ -96,3 +96,11 @@ var num = new Number<m>(),
9696
* Number
9797
* Boolean
9898
* Date
99+
100+
## Additional Considerations
101+
102+
It might be beneficial to have a type constraint on these defined types. For example:
103+
104+
```typescript
105+
declare type email : string;
106+
```

0 commit comments

Comments
 (0)