-
Notifications
You must be signed in to change notification settings - Fork 159
Closed
Description
MessagePart, the element type of MessageFormat#formatToParts's return type, expands to MessageBiDiIsolationPart | MessageExpressionPart | MessageLiteralPart | MessageMarkupPart, of which MessageExpressionPart's type property is simply string. As a result, the MessageParts have no ergonomic way of discriminating between the different types of message parts:
for (const part of new MessageFormat('en', 'hello world').formatToParts()) {
part.type
// ^ type: `string` (should be `'literal' | 'markup' | 'bidiIsolation' | ...other string literals`)
switch (part.type) {
case 'literal': {
part
// ^ type: `MessageLiteralPart | MessageExpressionPart` (should be `MessageLiteralPart` only)
break
}
case 'markup': {
part
// ^ type: `MessageMarkupPart | MessageExpressionPart` (should be `MessageMarkupPart` only)
break
}
case 'bidiIsolation': {
part
// ^ type: `MessageBiDiIsolationPart | MessageExpressionPart` (should be `MessageBiDiIsolationPart` only)
break
}
default: {
part
// ^ type: generic `MessagePart` (should be `MessageExpressionPart`, or better yet a union of finer-grained types)
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels