mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 05:17:43 -05:00
Get narrowable types for new expressions (#57382)
This commit is contained in:
committed by
GitHub
parent
f23927a806
commit
63dd17baef
@@ -29071,6 +29071,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return parent.kind === SyntaxKind.PropertyAccessExpression ||
|
||||
parent.kind === SyntaxKind.QualifiedName ||
|
||||
parent.kind === SyntaxKind.CallExpression && (parent as CallExpression).expression === node ||
|
||||
parent.kind === SyntaxKind.NewExpression && (parent as NewExpression).expression === node ||
|
||||
parent.kind === SyntaxKind.ElementAccessExpression && (parent as ElementAccessExpression).expression === node &&
|
||||
!(someType(type, isGenericTypeWithoutNullableConstraint) && isGenericIndexType(getTypeOfExpression((parent as ElementAccessExpression).argumentExpression)));
|
||||
}
|
||||
|
||||
@@ -82,6 +82,14 @@ function f5<T, K extends keyof T>(obj: T | undefined, key: K) {
|
||||
obj[key];
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/57381
|
||||
|
||||
function f6<T extends string | (new () => {})>(a: T) {
|
||||
if (typeof a !== "string") {
|
||||
new a();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [typeVariableTypeGuards.js]
|
||||
@@ -165,3 +173,9 @@ function f5(obj, key) {
|
||||
obj[key];
|
||||
}
|
||||
}
|
||||
// https://github.com/microsoft/TypeScript/issues/57381
|
||||
function f6(a) {
|
||||
if (typeof a !== "string") {
|
||||
new a();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,3 +221,19 @@ function f5<T, K extends keyof T>(obj: T | undefined, key: K) {
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/57381
|
||||
|
||||
function f6<T extends string | (new () => {})>(a: T) {
|
||||
>f6 : Symbol(f6, Decl(typeVariableTypeGuards.ts, 80, 1))
|
||||
>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 84, 12))
|
||||
>a : Symbol(a, Decl(typeVariableTypeGuards.ts, 84, 47))
|
||||
>T : Symbol(T, Decl(typeVariableTypeGuards.ts, 84, 12))
|
||||
|
||||
if (typeof a !== "string") {
|
||||
>a : Symbol(a, Decl(typeVariableTypeGuards.ts, 84, 47))
|
||||
|
||||
new a();
|
||||
>a : Symbol(a, Decl(typeVariableTypeGuards.ts, 84, 47))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -200,3 +200,21 @@ function f5<T, K extends keyof T>(obj: T | undefined, key: K) {
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/57381
|
||||
|
||||
function f6<T extends string | (new () => {})>(a: T) {
|
||||
>f6 : <T extends string | (new () => {})>(a: T) => void
|
||||
>a : T
|
||||
|
||||
if (typeof a !== "string") {
|
||||
>typeof a !== "string" : boolean
|
||||
>typeof a : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
|
||||
>a : T
|
||||
>"string" : "string"
|
||||
|
||||
new a();
|
||||
>new a() : {}
|
||||
>a : new () => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,3 +81,11 @@ function f5<T, K extends keyof T>(obj: T | undefined, key: K) {
|
||||
obj[key];
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/57381
|
||||
|
||||
function f6<T extends string | (new () => {})>(a: T) {
|
||||
if (typeof a !== "string") {
|
||||
new a();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user