Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cca34da

Browse files
committed
Give a name to InputType and use it
1 parent a95a03b commit cca34da

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
@@ -970,15 +970,13 @@ definition of "resolved value".
970970

971971
## Introducing type names
972972

973-
It's useful to be able to refer to two types:
973+
It's useful to be able to refer to three types:
974974

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

983981
It's tagged with a string tag so functions can do type checks.
984982

@@ -1017,8 +1015,10 @@ that functions can operate on.
10171015
The most ambitious solution is to specify
10181016
a type system for MessageFormat functions.
10191017

1020-
`ValueType` is the most general type
1018+
In this solution, `ValueType` is not what is defined above,
1019+
but instead is the most general type
10211020
in a system of user-defined types.
1021+
(The internal definitions are omitted.)
10221022
Using the function registry,
10231023
each custom function could declare its own argument type
10241024
and result type.
@@ -1077,6 +1077,15 @@ impractical.
10771077
In the preservation model,
10781078
functions "pipeline" the input through multiple calls.
10791079

1080+
The `ValueType` definition is different:
1081+
1082+
```ts
1083+
interface ValueType {
1084+
type(): string
1085+
value(): InputType | MessageValue
1086+
}
1087+
```
1088+
10801089
The resolved value interface would include both "input"
10811090
and "output" methods:
10821091

@@ -1086,7 +1095,7 @@ interface MessageValue {
10861095
formatToX(): X // where X is an implementation-defined type
10871096
getInput(): ValueType
10881097
getOutput(): ValueType
1089-
properties(): { [key: string]: MessageValue }
1098+
properties(): { [key: string]: ValueType }
10901099
selectKeys(keys: string[]): string[]
10911100
}
10921101
```
@@ -1100,7 +1109,7 @@ choose which options to pass through into the resulting
11001109
Instead of using `unknown` as the result type of `getValue()`,
11011110
we use `ValueType`, mentioned previously.
11021111
Instead of using `unknown` as the value type for the
1103-
`properties()` object, we use `MessageValue`,
1112+
`properties()` object, we use `ValueType`,
11041113
since options can also be full `MessageValue`s with their own options.
11051114

11061115
Without a mechanism for type signatures,
@@ -1137,8 +1146,8 @@ number : Number -> FormattedNumber
11371146
date : Date -> FormattedDate
11381147
```
11391148

1140-
The resolved value type would be the same as
1141-
in the formatted value model.
1149+
The `MessageValue` type would be defined the same way
1150+
as in the formatted value model.
11421151

11431152
The difference is that built-in functions
11441153
would not accept a "formatted result"

0 commit comments

Comments
 (0)