Proposal to add symbol: "hasInstanceStrict"

kdex kdex at kdex.de
Sun Feb 18 16:39:43 UTC 2018


Can you give some reasons why this, as opposed to static type checking, is 
worth pursuing at all?

On Sunday, February 18, 2018 5:30:42 PM CET Aleksander Efremov wrote:
> It’s attempt to provide intermediate layer for implementation of runtime
> type checking.
> 
> ```
> class PrimitiveNumber {
> 	static [Symbol.hasInstanceStrict](x) {
> 		if (typeof x !== ’number’) {
> 			throw new TypeError(‘Invalid type’);
> 		}
> 	}
> }
> 
> function sum(a: PrimitiveNumber, b: PrimitiveNumber) {
> 	return a + b;
> }
> 
> const c: PrimitiveNumber = sum(1, 2);
> ```
> 
> I.e. when appears assignment of variable (const) if then follows `: <class>`
> then JS runtime must to call method `static [Symbol.hasInstanceStrict](x)`
> and transfer to there assignable value.
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180218/7be4ac0e/attachment.sig>


More information about the es-discuss mailing list