add type guard of constructor#23622
Conversation
|
what should i do with |
I'd filter down to the primitive types (e.g. So declare let x: number | true | "hello" | "world;
if (x.constructor === String) {
// x has type `"hello" | "world"` here.
} |
| const targetType = !isTypeAny(prototypePropertyType) ? prototypePropertyType : undefined; | ||
| if (!targetType || isTypeAny(type) && (targetType === globalObjectType || targetType === globalFunctionType)) return type; | ||
|
|
||
| return getNarrowedType(type, targetType, assumeTrue, areTypesComparable); |
There was a problem hiding this comment.
I don't think you want areTypesComparable because this will work for types which don't explicitly derive from a given constructor.
I think you potentially want a helper function that uses isTypeDerivedFrom on the wrapper object type for any primitive types.
There was a problem hiding this comment.
will work for types which don't explicitly derive from a given constructor
could you give some example? 😢
| } | ||
|
|
||
| /** @internal */ | ||
| export function isExclamationEqualsOrExclamationEqualsEqualsKind(kind: SyntaxKind): boolean { |
There was a problem hiding this comment.
Maybe isNegatedEqualityToken? *shrug*
|
need take another look😢 |
|
🆙 |
77c3f73 to
49b364d
Compare
|
🆙 |
9f43125 to
cd7dd47
Compare
|
Cycling to get a fresh CI |
|
@Kingwl closing for housekeeping; would welcome a fresh PR |
Fixes #23274