Proposal to add symbol: "hasInstanceStrict"

Aleksander Efremov mr.efrem at gmail.com
Sun Feb 18 16:30:42 UTC 2018


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.



More information about the es-discuss mailing list