Skip to content

Add emu-note about why valueOf throws #1681

@justingrant

Description

@justingrant

js-temporal/temporal-polyfill#21 (comment) exposed an issue we should look at. The problem @12wrigja found is that when string interpolation is polyfilled by TS (and perhaps by Babel too?) it's converted to +, which per https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.valueof will throw.

throw new RangeError(Offset ${offsetStr} is invalid for ${dt} in ${timeZoneString}); is transpiled by tsc to throw new RangeError('Offset ' + offsetStr + ' is invalid for ' + dt + ' in ' + timeZoneString);, and the '+' operator invokes valueOf.

This implies that code using Temporal instances in string interpolations will work fine in native ES6 but will throw when polyfilled into ES5. Is this OK? If not, are there any ways around it (e.g. by using @@toPrimitive) ?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions