File tree Expand file tree Collapse file tree 3 files changed +46
-3
lines changed
tests/cases/conformance/externalModules/typeOnly Expand file tree Collapse file tree 3 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -1868,7 +1868,7 @@ namespace ts {
18681868 if (
18691869 !(useSite.flags & NodeFlags.Ambient) &&
18701870 !isPartOfTypeQuery(useSite) &&
1871- !isPartOfPossiblyValidComputedPropertyNameExpression (useSite) &&
1871+ !isPartOfPossiblyValidTypeOrAbstractComputedPropertyName (useSite) &&
18721872 isExpressionNode(useSite)
18731873 ) {
18741874 const typeOnlyDeclaration = getTypeOnlyAliasDeclaration(symbol);
Original file line number Diff line number Diff line change @@ -1778,11 +1778,22 @@ namespace ts {
17781778 return node . kind === SyntaxKind . TypeQuery ;
17791779 }
17801780
1781- export function isPartOfPossiblyValidComputedPropertyNameExpression ( node : Node ) {
1781+ export function isPartOfPossiblyValidTypeOrAbstractComputedPropertyName ( node : Node ) {
17821782 while ( node . kind === SyntaxKind . Identifier || node . kind === SyntaxKind . PropertyAccessExpression ) {
17831783 node = node . parent ;
17841784 }
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 ) ;
17861797 }
17871798
17881799 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";
99interface Component {
1010 [ onInit ] ?( ) : void ;
1111}
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