@@ -899,59 +899,42 @@ namespace ts.codefix {
899
899
if ( usage . isNumberOrString ) {
900
900
types . push ( checker . getUnionType ( [ checker . getStringType ( ) , checker . getNumberType ( ) ] ) ) ;
901
901
}
902
-
903
- types . push ( ...( usage . candidateTypes || [ ] ) . map ( t => checker . getBaseTypeOfLiteralType ( t ) ) ) ;
904
- types . push ( ...inferNamedTypesFromProperties ( usage ) ) ;
905
-
906
902
if ( usage . numberIndex ) {
907
903
types . push ( checker . createArrayType ( unifyFromUsage ( usage . numberIndex ) ) ) ;
908
904
}
909
- const structural = inferStructuralType ( usage ) ;
910
- if ( structural ) {
911
- types . push ( structural ) ;
905
+ if ( usage . properties && usage . properties . size
906
+ || usage . calls && usage . calls . length
907
+ || usage . constructs && usage . constructs . length
908
+ || usage . stringIndex ) {
909
+ types . push ( inferStructuralType ( usage ) ) ;
912
910
}
911
+
912
+ types . push ( ...( usage . candidateTypes || [ ] ) . map ( t => checker . getBaseTypeOfLiteralType ( t ) ) ) ;
913
+ types . push ( ...inferNamedTypesFromProperties ( usage ) ) ;
914
+
913
915
return types ;
914
916
}
915
917
916
918
function inferStructuralType ( usage : Usage ) {
917
- if ( usage . properties && usage . properties . size
918
- || usage . calls && usage . calls . length
919
- || usage . constructs && usage . constructs . length
920
- || usage . stringIndex ) {
921
- const members = createUnderscoreEscapedMap < Symbol > ( ) ;
922
- const callSignatures : Signature [ ] = [ ] ;
923
- const constructSignatures : Signature [ ] = [ ] ;
924
- let stringIndexInfo : IndexInfo | undefined ;
925
-
926
- if ( usage . properties ) {
927
- usage . properties . forEach ( ( u , name ) => {
928
- const symbol = checker . createSymbol ( SymbolFlags . Property , name ) ;
929
- symbol . type = unifyFromUsage ( u ) ;
930
- members . set ( name , symbol ) ;
931
- } ) ;
932
- }
933
-
934
- if ( usage . calls ) {
935
- callSignatures . push ( getSignatureFromCalls ( usage . calls ) ) ;
936
- }
937
-
938
- if ( usage . constructs ) {
939
- constructSignatures . push ( getSignatureFromCalls ( usage . constructs ) ) ;
940
- }
941
-
942
- if ( usage . stringIndex ) {
943
- stringIndexInfo = checker . createIndexInfo ( unifyFromUsage ( usage . stringIndex ) , /*isReadonly*/ false ) ;
944
- }
945
-
946
- return checker . createAnonymousType ( /*symbol*/ undefined ! , members , callSignatures , constructSignatures , stringIndexInfo , /*numberIndexInfo*/ undefined ) ; // TODO: GH#18217
919
+ const members = createUnderscoreEscapedMap < Symbol > ( ) ;
920
+ if ( usage . properties ) {
921
+ usage . properties . forEach ( ( u , name ) => {
922
+ const symbol = checker . createSymbol ( SymbolFlags . Property , name ) ;
923
+ symbol . type = unifyFromUsage ( u ) ;
924
+ members . set ( name , symbol ) ;
925
+ } ) ;
947
926
}
927
+ const callSignatures : Signature [ ] = usage . calls ? [ getSignatureFromCalls ( usage . calls ) ] : [ ] ;
928
+ const constructSignatures : Signature [ ] = usage . constructs ? [ getSignatureFromCalls ( usage . constructs ) ] : [ ] ;
929
+ const stringIndexInfo = usage . stringIndex && checker . createIndexInfo ( unifyFromUsage ( usage . stringIndex ) , /*isReadonly*/ false ) ;
930
+ return checker . createAnonymousType ( /*symbol*/ undefined ! , members , callSignatures , constructSignatures , stringIndexInfo , /*numberIndexInfo*/ undefined ) ; // TODO: GH#18217
948
931
}
949
932
950
933
function inferNamedTypesFromProperties ( usage : Usage ) : Type [ ] {
951
934
if ( ! usage . properties || ! usage . properties . size ) return [ ] ;
952
- const matches = builtins . filter ( t => allPropertiesAreAssignableToUsage ( t , usage ) ) ;
953
- if ( 0 < matches . length && matches . length < 3 ) {
954
- return matches . map ( m => inferInstantiationFromUsage ( m , usage ) ) ;
935
+ const types = builtins . filter ( t => allPropertiesAreAssignableToUsage ( t , usage ) ) ;
936
+ if ( 0 < types . length && types . length < 3 ) {
937
+ return types . map ( t => inferInstantiationFromUsage ( t , usage ) ) ;
955
938
}
956
939
return [ ] ;
957
940
}
0 commit comments