* Implement constructor type guard * Fix code review issues for constructor type guard. - Do not limit constructor expression to only identifiers - Fix `assumeTrue` and operator no-narrow check - Use better way to check that identifier type is a function - Loosen restriction on what expr is left of ".constructor" - Update typeGuardConstructorClassAndNumber test to include else cases * Fix grammar & spacing in `narrowTypeByConstructor` * fix bad merge * switch (back?) to crlf * update baselines Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
24 lines
432 B
TypeScript
24 lines
432 B
TypeScript
// @target: esnext
|
|
|
|
// Narrowing any to primitives
|
|
let var1: any;
|
|
|
|
if (var1.constructor === String) {
|
|
var1; // String
|
|
}
|
|
if (var1.constructor === Number) {
|
|
var1; // Number
|
|
}
|
|
if (var1.constructor === Boolean) {
|
|
var1; // Boolean
|
|
}
|
|
if (var1.constructor === Array) {
|
|
var1; // any[]
|
|
}
|
|
if (var1.constructor === Symbol) {
|
|
var1; // Symbol
|
|
}
|
|
if (var1.constructor === BigInt) {
|
|
var1; // BigInt
|
|
}
|