mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 12:32:08 -06:00
Fixed narrowing based on aliased discriminants coming from destructured parameters (#56860)
This commit is contained in:
parent
01a51d2d01
commit
5a355093bb
@ -476,6 +476,7 @@ import {
|
||||
isCallOrNewExpression,
|
||||
isCallSignatureDeclaration,
|
||||
isCatchClause,
|
||||
isCatchClauseVariableDeclaration,
|
||||
isCatchClauseVariableDeclarationOrBindingElement,
|
||||
isCheckJsEnabledForFile,
|
||||
isClassDeclaration,
|
||||
@ -27490,7 +27491,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
const rootDeclaration = getRootDeclaration(node.parent);
|
||||
return isVariableDeclaration(rootDeclaration) && isVarConstLike(rootDeclaration);
|
||||
return isParameter(rootDeclaration) || isCatchClauseVariableDeclaration(rootDeclaration)
|
||||
? !isSomeSymbolAssigned(rootDeclaration)
|
||||
: isVariableDeclaration(rootDeclaration) && isVarConstLike(rootDeclaration);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -126,4 +126,14 @@ controlFlowAliasedDiscriminants.ts(98,19): error TS1360: Type 'string | number'
|
||||
resp.resp.data satisfies string;
|
||||
}
|
||||
}
|
||||
|
||||
function bindingPatternInParameter({ data: data1, isSuccess: isSuccess1 }: UseQueryResult<number>) {
|
||||
const { data: data2, isSuccess: isSuccess2 } = useQuery();
|
||||
|
||||
const areSuccess = isSuccess1 && isSuccess2;
|
||||
if (areSuccess) {
|
||||
data1.toExponential();
|
||||
data2.toExponential();
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,9 +104,20 @@ type Nested = {
|
||||
resp.resp.data satisfies string;
|
||||
}
|
||||
}
|
||||
|
||||
function bindingPatternInParameter({ data: data1, isSuccess: isSuccess1 }: UseQueryResult<number>) {
|
||||
const { data: data2, isSuccess: isSuccess2 } = useQuery();
|
||||
|
||||
const areSuccess = isSuccess1 && isSuccess2;
|
||||
if (areSuccess) {
|
||||
data1.toExponential();
|
||||
data2.toExponential();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [controlFlowAliasedDiscriminants.js]
|
||||
"use strict";
|
||||
function useQuery() {
|
||||
return {
|
||||
isSuccess: false,
|
||||
@ -180,3 +191,12 @@ if (areSuccess) {
|
||||
resp.resp.data;
|
||||
}
|
||||
}
|
||||
function bindingPatternInParameter(_a) {
|
||||
var data1 = _a.data, isSuccess1 = _a.isSuccess;
|
||||
var _b = useQuery(), data2 = _b.data, isSuccess2 = _b.isSuccess;
|
||||
var areSuccess = isSuccess1 && isSuccess2;
|
||||
if (areSuccess) {
|
||||
data1.toExponential();
|
||||
data2.toExponential();
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,3 +325,38 @@ type Nested = {
|
||||
}
|
||||
}
|
||||
|
||||
function bindingPatternInParameter({ data: data1, isSuccess: isSuccess1 }: UseQueryResult<number>) {
|
||||
>bindingPatternInParameter : Symbol(bindingPatternInParameter, Decl(controlFlowAliasedDiscriminants.ts, 102, 1))
|
||||
>data : Symbol(data, Decl(controlFlowAliasedDiscriminants.ts, 1, 21), Decl(controlFlowAliasedDiscriminants.ts, 4, 20))
|
||||
>data1 : Symbol(data1, Decl(controlFlowAliasedDiscriminants.ts, 104, 36))
|
||||
>isSuccess : Symbol(isSuccess, Decl(controlFlowAliasedDiscriminants.ts, 0, 26), Decl(controlFlowAliasedDiscriminants.ts, 3, 5))
|
||||
>isSuccess1 : Symbol(isSuccess1, Decl(controlFlowAliasedDiscriminants.ts, 104, 49))
|
||||
>UseQueryResult : Symbol(UseQueryResult, Decl(controlFlowAliasedDiscriminants.ts, 0, 0))
|
||||
|
||||
const { data: data2, isSuccess: isSuccess2 } = useQuery();
|
||||
>data : Symbol(data, Decl(controlFlowAliasedDiscriminants.ts, 1, 21), Decl(controlFlowAliasedDiscriminants.ts, 4, 20))
|
||||
>data2 : Symbol(data2, Decl(controlFlowAliasedDiscriminants.ts, 105, 9))
|
||||
>isSuccess : Symbol(isSuccess, Decl(controlFlowAliasedDiscriminants.ts, 0, 26), Decl(controlFlowAliasedDiscriminants.ts, 3, 5))
|
||||
>isSuccess2 : Symbol(isSuccess2, Decl(controlFlowAliasedDiscriminants.ts, 105, 22))
|
||||
>useQuery : Symbol(useQuery, Decl(controlFlowAliasedDiscriminants.ts, 6, 2))
|
||||
|
||||
const areSuccess = isSuccess1 && isSuccess2;
|
||||
>areSuccess : Symbol(areSuccess, Decl(controlFlowAliasedDiscriminants.ts, 107, 7))
|
||||
>isSuccess1 : Symbol(isSuccess1, Decl(controlFlowAliasedDiscriminants.ts, 104, 49))
|
||||
>isSuccess2 : Symbol(isSuccess2, Decl(controlFlowAliasedDiscriminants.ts, 105, 22))
|
||||
|
||||
if (areSuccess) {
|
||||
>areSuccess : Symbol(areSuccess, Decl(controlFlowAliasedDiscriminants.ts, 107, 7))
|
||||
|
||||
data1.toExponential();
|
||||
>data1.toExponential : Symbol(Number.toExponential, Decl(lib.es5.d.ts, --, --))
|
||||
>data1 : Symbol(data1, Decl(controlFlowAliasedDiscriminants.ts, 104, 36))
|
||||
>toExponential : Symbol(Number.toExponential, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
data2.toExponential();
|
||||
>data2.toExponential : Symbol(Number.toExponential, Decl(lib.es5.d.ts, --, --))
|
||||
>data2 : Symbol(data2, Decl(controlFlowAliasedDiscriminants.ts, 105, 9))
|
||||
>toExponential : Symbol(Number.toExponential, Decl(lib.es5.d.ts, --, --))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -376,3 +376,41 @@ type Nested = {
|
||||
}
|
||||
}
|
||||
|
||||
function bindingPatternInParameter({ data: data1, isSuccess: isSuccess1 }: UseQueryResult<number>) {
|
||||
>bindingPatternInParameter : ({ data: data1, isSuccess: isSuccess1 }: UseQueryResult<number>) => void
|
||||
>data : any
|
||||
>data1 : number | undefined
|
||||
>isSuccess : any
|
||||
>isSuccess1 : boolean
|
||||
|
||||
const { data: data2, isSuccess: isSuccess2 } = useQuery();
|
||||
>data : any
|
||||
>data2 : number | undefined
|
||||
>isSuccess : any
|
||||
>isSuccess2 : boolean
|
||||
>useQuery() : UseQueryResult<number>
|
||||
>useQuery : () => UseQueryResult<number>
|
||||
|
||||
const areSuccess = isSuccess1 && isSuccess2;
|
||||
>areSuccess : boolean
|
||||
>isSuccess1 && isSuccess2 : boolean
|
||||
>isSuccess1 : boolean
|
||||
>isSuccess2 : boolean
|
||||
|
||||
if (areSuccess) {
|
||||
>areSuccess : boolean
|
||||
|
||||
data1.toExponential();
|
||||
>data1.toExponential() : string
|
||||
>data1.toExponential : (fractionDigits?: number | undefined) => string
|
||||
>data1 : number
|
||||
>toExponential : (fractionDigits?: number | undefined) => string
|
||||
|
||||
data2.toExponential();
|
||||
>data2.toExponential() : string
|
||||
>data2.toExponential : (fractionDigits?: number | undefined) => string
|
||||
>data2 : number
|
||||
>toExponential : (fractionDigits?: number | undefined) => string
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
// @strictNullChecks: true
|
||||
// @noImplicitAny: true
|
||||
// @strict: true
|
||||
|
||||
type UseQueryResult<T> = {
|
||||
isSuccess: false;
|
||||
@ -104,3 +103,13 @@ type Nested = {
|
||||
resp.resp.data satisfies string;
|
||||
}
|
||||
}
|
||||
|
||||
function bindingPatternInParameter({ data: data1, isSuccess: isSuccess1 }: UseQueryResult<number>) {
|
||||
const { data: data2, isSuccess: isSuccess2 } = useQuery();
|
||||
|
||||
const areSuccess = isSuccess1 && isSuccess2;
|
||||
if (areSuccess) {
|
||||
data1.toExponential();
|
||||
data2.toExponential();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user