Skip to content

Commit 34b5723

Browse files
committed
Give a name to InputType and use it
1 parent aaff56c commit 34b5723

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

exploration/function-composition-part-1.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,13 @@ definition of "resolved value".
980980

981981
## Introducing type names
982982

983-
It's useful to be able to refer to two types:
983+
It's useful to be able to refer to three types:
984984

985-
* `MessageValue`: The "resolved value" type; see [PR 728](https://github.com/unicode-org/message-format-wg/pull/728).
986-
* `ValueType`: This type encompasses strings, numbers, date/time values,
985+
* `InputType`: This type encompasses strings, numbers, date/time values,
987986
all other possible implementation-specific types that input variables can be
988-
assigned to,
989-
and all possible implementation-specific types that custom and built-in
990-
functions can construct.
991-
Conceptually it's the union of an "input type" and a "formatted value".
987+
assigned to. The details are implementation-specific.
988+
* `MessageValue`: The "resolved value" type; see [PR 728](https://github.com/unicode-org/message-format-wg/pull/728).
989+
* `ValueType`: This type is the union of an `InputType` and a `MessageValue`.
992990

993991
It's tagged with a string tag so functions can do type checks.
994992

@@ -1027,8 +1025,10 @@ that functions can operate on.
10271025
The most ambitious solution is to specify
10281026
a type system for MessageFormat functions.
10291027

1030-
`ValueType` is the most general type
1028+
In this solution, `ValueType` is not what is defined above,
1029+
but instead is the most general type
10311030
in a system of user-defined types.
1031+
(The internal definitions are omitted.)
10321032
Using the function registry,
10331033
each custom function could declare its own argument type
10341034
and result type.
@@ -1087,6 +1087,15 @@ impractical.
10871087
In the preservation model,
10881088
functions "pipeline" the input through multiple calls.
10891089

1090+
The `ValueType` definition is different:
1091+
1092+
```ts
1093+
interface ValueType {
1094+
type(): string
1095+
value(): InputType | MessageValue
1096+
}
1097+
```
1098+
10901099
The resolved value interface would include both "input"
10911100
and "output" methods:
10921101

@@ -1096,7 +1105,7 @@ interface MessageValue {
10961105
formatToX(): X // where X is an implementation-defined type
10971106
getInput(): ValueType
10981107
getOutput(): ValueType
1099-
properties(): { [key: string]: MessageValue }
1108+
properties(): { [key: string]: ValueType }
11001109
selectKeys(keys: string[]): string[]
11011110
}
11021111
```
@@ -1110,7 +1119,7 @@ choose which options to pass through into the resulting
11101119
Instead of using `unknown` as the result type of `getValue()`,
11111120
we use `ValueType`, mentioned previously.
11121121
Instead of using `unknown` as the value type for the
1113-
`properties()` object, we use `MessageValue`,
1122+
`properties()` object, we use `ValueType`,
11141123
since options can also be full `MessageValue`s with their own options.
11151124

11161125
Without a mechanism for type signatures,
@@ -1147,8 +1156,8 @@ number : Number -> FormattedNumber
11471156
date : Date -> FormattedDate
11481157
```
11491158

1150-
The resolved value type would be the same as
1151-
in the formatted value model.
1159+
The `MessageValue` type would be defined the same way
1160+
as in the formatted value model.
11521161

11531162
The difference is that built-in functions
11541163
would not accept a "formatted result"

0 commit comments

Comments
 (0)