diff --git a/packages/uni-uts-v1/lib/typescript/lib/typescript.factory.js b/packages/uni-uts-v1/lib/typescript/lib/typescript.factory.js index a48287b4161..bd9a1eea6c1 100644 --- a/packages/uni-uts-v1/lib/typescript/lib/typescript.factory.js +++ b/packages/uni-uts-v1/lib/typescript/lib/typescript.factory.js @@ -46175,8 +46175,33 @@ ${lanes.join("\n")} markSymbolAsNotTypeOnly, // fix by uts 暴露此方法,用于获取错误类型 // @ts-ignore - getErrorType: () => errorType + getErrorType: () => errorType, + // fix by uts 暴露此方法,用于收窄 in 操作符 + narrowTypeByInKeyword }; + function isTypePresencePossible(type, propName, assumeTrue) { + const prop = getPropertyOfType(type, propName); + return prop ? !!(prop.flags & 16777216 /* Optional */ || getCheckFlags(prop) & 48 /* Partial */) || assumeTrue : !!getApplicableIndexInfoForName(type, propName) || !assumeTrue; + } + function narrowTypeByInKeyword(type, nameType, assumeTrue) { + const name = getPropertyNameFromType(nameType); + const isKnownProperty2 = someType(type, (t) => isTypePresencePossible( + t, + name, + /*assumeTrue*/ + true + )); + if (isKnownProperty2) { + return filterType(type, (t) => isTypePresencePossible(t, name, assumeTrue)); + } + if (assumeTrue) { + const recordSymbol = getGlobalRecordSymbol(); + if (recordSymbol) { + return getIntersectionType([type, getTypeAliasInstantiation(recordSymbol, [nameType, unknownType])]); + } + } + return type; + } function runWithoutResolvedSignatureCaching(node, fn) { const cachedSignatures = []; while (node) { @@ -68352,20 +68377,20 @@ ${lanes.join("\n")} } return type; } - function isTypePresencePossible(type, propName, assumeTrue) { + function isTypePresencePossible2(type, propName, assumeTrue) { const prop = getPropertyOfType(type, propName); return prop ? !!(prop.flags & 16777216 /* Optional */ || getCheckFlags(prop) & 48 /* Partial */) || assumeTrue : !!getApplicableIndexInfoForName(type, propName) || !assumeTrue; } - function narrowTypeByInKeyword(type, nameType, assumeTrue) { + function narrowTypeByInKeyword2(type, nameType, assumeTrue) { const name = getPropertyNameFromType(nameType); - const isKnownProperty2 = someType(type, (t) => isTypePresencePossible( + const isKnownProperty2 = someType(type, (t) => isTypePresencePossible2( t, name, /*assumeTrue*/ true )); if (isKnownProperty2) { - return filterType(type, (t) => isTypePresencePossible(t, name, assumeTrue)); + return filterType(type, (t) => isTypePresencePossible2(t, name, assumeTrue)); } if (assumeTrue) { const recordSymbol = getGlobalRecordSymbol(); @@ -68439,7 +68464,7 @@ ${lanes.join("\n")} if (isMatchingReference(reference, target)) { const leftType = getTypeOfExpression(expr.left); if (isTypeUsableAsPropertyName(leftType)) { - return narrowTypeByInKeyword(type, leftType, assumeTrue); + return narrowTypeByInKeyword2(type, leftType, assumeTrue); } } break; diff --git a/packages/uni-uts-v1/lib/typescript/lib/typescript.js b/packages/uni-uts-v1/lib/typescript/lib/typescript.js index 4464c067066..46efc1d6dcf 100644 --- a/packages/uni-uts-v1/lib/typescript/lib/typescript.js +++ b/packages/uni-uts-v1/lib/typescript/lib/typescript.js @@ -46172,8 +46172,33 @@ ${lanes.join("\n")} markSymbolAsNotTypeOnly, // fix by uts 暴露此方法,用于获取错误类型 // @ts-ignore - getErrorType: () => errorType + getErrorType: () => errorType, + // fix by uts 暴露此方法,用于收窄 in 操作符 + narrowTypeByInKeyword }; + function isTypePresencePossible(type, propName, assumeTrue) { + const prop = getPropertyOfType(type, propName); + return prop ? !!(prop.flags & 16777216 /* Optional */ || getCheckFlags(prop) & 48 /* Partial */) || assumeTrue : !!getApplicableIndexInfoForName(type, propName) || !assumeTrue; + } + function narrowTypeByInKeyword(type, nameType, assumeTrue) { + const name = getPropertyNameFromType(nameType); + const isKnownProperty2 = someType(type, (t) => isTypePresencePossible( + t, + name, + /*assumeTrue*/ + true + )); + if (isKnownProperty2) { + return filterType(type, (t) => isTypePresencePossible(t, name, assumeTrue)); + } + if (assumeTrue) { + const recordSymbol = getGlobalRecordSymbol(); + if (recordSymbol) { + return getIntersectionType([type, getTypeAliasInstantiation(recordSymbol, [nameType, unknownType])]); + } + } + return type; + } function runWithoutResolvedSignatureCaching(node, fn) { const cachedSignatures = []; while (node) { @@ -68349,20 +68374,20 @@ ${lanes.join("\n")} } return type; } - function isTypePresencePossible(type, propName, assumeTrue) { + function isTypePresencePossible2(type, propName, assumeTrue) { const prop = getPropertyOfType(type, propName); return prop ? !!(prop.flags & 16777216 /* Optional */ || getCheckFlags(prop) & 48 /* Partial */) || assumeTrue : !!getApplicableIndexInfoForName(type, propName) || !assumeTrue; } - function narrowTypeByInKeyword(type, nameType, assumeTrue) { + function narrowTypeByInKeyword2(type, nameType, assumeTrue) { const name = getPropertyNameFromType(nameType); - const isKnownProperty2 = someType(type, (t) => isTypePresencePossible( + const isKnownProperty2 = someType(type, (t) => isTypePresencePossible2( t, name, /*assumeTrue*/ true )); if (isKnownProperty2) { - return filterType(type, (t) => isTypePresencePossible(t, name, assumeTrue)); + return filterType(type, (t) => isTypePresencePossible2(t, name, assumeTrue)); } if (assumeTrue) { const recordSymbol = getGlobalRecordSymbol(); @@ -68436,7 +68461,7 @@ ${lanes.join("\n")} if (isMatchingReference(reference, target)) { const leftType = getTypeOfExpression(expr.left); if (isTypeUsableAsPropertyName(leftType)) { - return narrowTypeByInKeyword(type, leftType, assumeTrue); + return narrowTypeByInKeyword2(type, leftType, assumeTrue); } } break; diff --git a/packages/uni-uts-v1/lib/uni-x/dist/compiler.js b/packages/uni-uts-v1/lib/uni-x/dist/compiler.js index 41510d95b89..5044c5fb955 100644 --- a/packages/uni-uts-v1/lib/uni-x/dist/compiler.js +++ b/packages/uni-uts-v1/lib/uni-x/dist/compiler.js @@ -1 +1 @@ -"use strict";require("fs");var e,t,r=require("debug"),n=require("path"),i=require("fs-extra"),s=require("source-map-js");function o(e){return e.replace(/\\/g,"/")}function a(e,t,r,n,i,s,o){return{code:e,category:t,key:r,message:n,reportsUnnecessary:i,elidedInCompatabilityPyramid:s,reportsDeprecated:o}}function c(e){let t,r=()=>{};return t=e?Promise.race([new Promise((t=>setTimeout(t,e,!0))),new Promise((e=>r=e))]):new Promise((e=>r=e)),{promise:t,resolve:r}}!function(e){e[e.Warning=0]="Warning",e[e.Error=1]="Error",e[e.Suggestion=2]="Suggestion",e[e.Message=3]="Message"}(e||(e={})),a(1e5,e.Error,"Type_literal_property_must_have_a_type_annotation_100000","Type literal property must have a type annotation."),a(100001,e.Error,"Only_one_extends_heritage_clause_is_allowed_for_interface_100001","Only one extends heritage clause is allowed for interface"),a(100002,e.Error,"Variable_declaration_must_have_initializer_100002","Variable declaration must have initializer."),a(100003,e.Error,"Nested_type_literal_is_not_supported_100003","Nested type literal is not supported."),a(100004,e.Error,"Invalid_generic_type_which_can_not_be_constructed_100004","Invalid generic type which can not be constructed."),a(100005,e.Error,"script_setup_cannot_contain_ES_module_exports_100005","`