@@ -1279,7 +1279,14 @@ namespace ts.Completions {
1279
1279
// Cursor is inside a JSX self-closing element or opening element
1280
1280
const attrsType = jsxContainer && typeChecker . getContextualType ( jsxContainer . attributes ) ;
1281
1281
if ( ! attrsType ) return GlobalsSearch . Continue ;
1282
- const baseType = jsxContainer && typeChecker . getContextualType ( jsxContainer . attributes , ContextFlags . BaseConstraint ) ;
1282
+ const uninstantiatedType = typeChecker . getContextualType ( jsxContainer ! , ContextFlags . Uninstantiated ) ;
1283
+ let baseType ;
1284
+ if ( uninstantiatedType ) {
1285
+ const signature = tryGetContextualTypeProvidingSignature ( jsxContainer ! , typeChecker ) ?. target ;
1286
+ if ( signature && ! isIndexedAccessTypeWithTypeParameterIndex ( uninstantiatedType , signature ) ) {
1287
+ baseType = typeChecker . getContextualType ( jsxContainer ! . attributes , ContextFlags . BaseConstraint ) ;
1288
+ }
1289
+ }
1283
1290
symbols = filterJsxAttributes ( getPropertiesForObjectExpression ( attrsType , baseType , jsxContainer ! . attributes , typeChecker ) , jsxContainer ! . attributes . properties ) ;
1284
1291
setSortTextToOptionalMember ( ) ;
1285
1292
completionKind = CompletionKind . MemberLike ;
@@ -1803,8 +1810,11 @@ namespace ts.Completions {
1803
1810
if ( ! instantiatedType ) return GlobalsSearch . Fail ;
1804
1811
const uninstantiatedType = typeChecker . getContextualType ( objectLikeContainer , ContextFlags . Uninstantiated ) ;
1805
1812
let baseType ;
1806
- if ( ! ( uninstantiatedType && uninstantiatedType . flags & TypeFlags . IndexedAccess ) ) {
1807
- baseType = typeChecker . getContextualType ( objectLikeContainer , ContextFlags . BaseConstraint ) ;
1813
+ if ( uninstantiatedType ) {
1814
+ const signature = tryGetContextualTypeProvidingSignature ( objectLikeContainer , typeChecker ) ?. target ;
1815
+ if ( signature && ! isIndexedAccessTypeWithTypeParameterIndex ( uninstantiatedType , signature ) ) {
1816
+ baseType = typeChecker . getContextualType ( objectLikeContainer , ContextFlags . BaseConstraint ) ;
1817
+ }
1808
1818
}
1809
1819
1810
1820
isNewIdentifierLocation = hasIndexSignature ( instantiatedType ) ;
@@ -1857,6 +1867,62 @@ namespace ts.Completions {
1857
1867
return GlobalsSearch . Success ;
1858
1868
}
1859
1869
1870
+ function tryGetContextualTypeProvidingSignature ( node : Node , checker : TypeChecker ) : Signature | undefined {
1871
+ loop: while ( true ) {
1872
+ switch ( node . kind ) {
1873
+ case SyntaxKind . SpreadAssignment :
1874
+ case SyntaxKind . ArrayLiteralExpression :
1875
+ case SyntaxKind . ParenthesizedExpression :
1876
+ case SyntaxKind . ConditionalExpression :
1877
+ case SyntaxKind . PropertyAssignment :
1878
+ case SyntaxKind . ShorthandPropertyAssignment :
1879
+ case SyntaxKind . ObjectLiteralExpression :
1880
+ case SyntaxKind . JsxAttribute :
1881
+ case SyntaxKind . JsxAttributes :
1882
+ node = node . parent ;
1883
+ break ;
1884
+ default :
1885
+ break loop;
1886
+ }
1887
+ }
1888
+ if ( ! isCallLikeExpression ( node ) && ! isJsxOpeningLikeElement ( node ) ) {
1889
+ return ;
1890
+ }
1891
+ return checker . getResolvedSignature ( node ) ;
1892
+ }
1893
+
1894
+ function isIndexedAccessTypeWithTypeParameterIndex ( type : Type , signature : Signature ) : boolean {
1895
+ if ( type . isUnionOrIntersection ( ) ) {
1896
+ return some ( type . types , t => isIndexedAccessTypeWithTypeParameterIndex ( t , signature ) ) ;
1897
+ }
1898
+ if ( type . flags & TypeFlags . IndexedAccess ) {
1899
+ return typeIsTypeParameterFromSignature ( ( type as IndexedAccessType ) . indexType , signature ) ;
1900
+ }
1901
+ return false ;
1902
+ }
1903
+
1904
+ function typeIsTypeParameterFromSignature ( type : Type , signature : Signature ) : boolean {
1905
+ if ( ! signature . typeParameters ) {
1906
+ return false ;
1907
+ }
1908
+ if ( type . isUnionOrIntersection ( ) ) {
1909
+ return some ( type . types , t => typeIsTypeParameterFromSignature ( t , signature ) ) ;
1910
+ }
1911
+ if ( type . flags & TypeFlags . Conditional ) {
1912
+ return typeIsTypeParameterFromSignature ( ( type as ConditionalType ) . checkType , signature )
1913
+ || typeIsTypeParameterFromSignature ( ( type as ConditionalType ) . extendsType , signature )
1914
+ || typeIsTypeParameterFromSignature ( ( type as ConditionalType ) . resolvedTrueType , signature )
1915
+ || typeIsTypeParameterFromSignature ( ( type as ConditionalType ) . resolvedFalseType , signature ) ;
1916
+ }
1917
+ if ( type . flags & TypeFlags . Index ) {
1918
+ return typeIsTypeParameterFromSignature ( ( type as IndexType ) . type , signature ) ;
1919
+ }
1920
+ if ( type . flags & TypeFlags . TypeParameter ) {
1921
+ return some ( signature . typeParameters , p => p . symbol === type . symbol ) ;
1922
+ }
1923
+ return false ;
1924
+ }
1925
+
1860
1926
/**
1861
1927
* Aggregates relevant symbols for completion in import clauses and export clauses
1862
1928
* whose declarations have a module specifier; for instance, symbols will be aggregated for
0 commit comments