File tree 3 files changed +46
-3
lines changed
tests/cases/conformance/externalModules/typeOnly
3 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -1868,7 +1868,7 @@ namespace ts {
1868
1868
if (
1869
1869
!(useSite.flags & NodeFlags.Ambient) &&
1870
1870
!isPartOfTypeQuery(useSite) &&
1871
- !isPartOfPossiblyValidComputedPropertyNameExpression (useSite) &&
1871
+ !isPartOfPossiblyValidTypeOrAbstractComputedPropertyName (useSite) &&
1872
1872
isExpressionNode(useSite)
1873
1873
) {
1874
1874
const typeOnlyDeclaration = getTypeOnlyAliasDeclaration(symbol);
Original file line number Diff line number Diff line change @@ -1778,11 +1778,22 @@ namespace ts {
1778
1778
return node . kind === SyntaxKind . TypeQuery ;
1779
1779
}
1780
1780
1781
- export function isPartOfPossiblyValidComputedPropertyNameExpression ( node : Node ) {
1781
+ export function isPartOfPossiblyValidTypeOrAbstractComputedPropertyName ( node : Node ) {
1782
1782
while ( node . kind === SyntaxKind . Identifier || node . kind === SyntaxKind . PropertyAccessExpression ) {
1783
1783
node = node . parent ;
1784
1784
}
1785
- return node . kind === SyntaxKind . ComputedPropertyName ;
1785
+ if ( node . kind !== SyntaxKind . ComputedPropertyName ) {
1786
+ return false ;
1787
+ }
1788
+ if ( hasModifier ( node . parent , ModifierFlags . Abstract ) ) {
1789
+ return true ;
1790
+ }
1791
+ const containerKind = node . parent . parent . kind ;
1792
+ return containerKind === SyntaxKind . InterfaceDeclaration || containerKind === SyntaxKind . TypeLiteral ;
1793
+ }
1794
+
1795
+ export function isAbstractDeclarationName ( node : Node ) {
1796
+ return isDeclarationName ( node ) && hasModifier ( node , ModifierFlags . Abstract ) ;
1786
1797
}
1787
1798
1788
1799
export function isExternalModuleImportEqualsDeclaration ( node : Node ) : node is ImportEqualsDeclaration & { moduleReference : ExternalModuleReference } {
Original file line number Diff line number Diff line change @@ -9,3 +9,35 @@ import type { onInit } from "./framework-hooks";
9
9
interface Component {
10
10
[ onInit ] ?( ) : void ;
11
11
}
12
+
13
+ type T = {
14
+ [ onInit ] : any ;
15
+ }
16
+
17
+ const o = {
18
+ [ onInit ] : 0 // Error
19
+ } ;
20
+
21
+ class C {
22
+ [ onInit ] : any ; // Error (because class fields)
23
+ }
24
+
25
+ class D {
26
+ [ onInit ] = 0 ; // Error
27
+ }
28
+
29
+ class E {
30
+ [ onInit ] ( ) { } // Error
31
+ }
32
+
33
+ abstract class F {
34
+ abstract [ onInit ] ( ) : void ;
35
+ }
36
+
37
+ class G {
38
+ declare [ onInit ] : any ;
39
+ }
40
+
41
+ declare class H {
42
+ [ onInit ] : any ;
43
+ }
You can’t perform that action at this time.
0 commit comments