Skip to content

Commit 87565da

Browse files
committed
Props of class A usable in prop initializer of class B
Regardless of the order of declaration of class A and class B.
1 parent 5e4b8d6 commit 87565da

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ namespace ts {
717717
}
718718
// declaration is after usage
719719
// can be legal if usage is deferred (i.e. inside function or in initializer of instance property)
720-
if (isUsedInFunctionOrInstanceProperty(usage)) {
720+
if (isUsedInFunctionOrInstanceProperty(usage, declaration)) {
721721
return true;
722722
}
723723
const sourceFiles = host.getSourceFiles();
@@ -748,8 +748,7 @@ namespace ts {
748748
// 1. inside a function
749749
// 2. inside an instance property initializer, a reference to a non-instance property
750750
const container = getEnclosingBlockScopeContainer(declaration);
751-
const isInstanceProperty = declaration.kind === SyntaxKind.PropertyDeclaration && !(getModifierFlags(declaration) & ModifierFlags.Static);
752-
return isUsedInFunctionOrInstanceProperty(usage, isInstanceProperty, container);
751+
return isUsedInFunctionOrInstanceProperty(usage, declaration, container);
753752

754753
function isImmediatelyUsedInInitializerOfBlockScopedVariable(declaration: VariableDeclaration, usage: Node): boolean {
755754
const container = getEnclosingBlockScopeContainer(declaration);
@@ -778,7 +777,7 @@ namespace ts {
778777
return false;
779778
}
780779

781-
function isUsedInFunctionOrInstanceProperty(usage: Node, isDeclarationInstanceProperty?: boolean, container?: Node): boolean {
780+
function isUsedInFunctionOrInstanceProperty(usage: Node, declaration: Node, container?: Node): boolean {
782781
let current = usage;
783782
while (current) {
784783
if (current === container) {
@@ -795,7 +794,8 @@ namespace ts {
795794
(<PropertyDeclaration>current.parent).initializer === current;
796795

797796
if (initializerOfInstanceProperty) {
798-
return !isDeclarationInstanceProperty;
797+
const isDeclarationInstanceProperty = declaration.kind === SyntaxKind.PropertyDeclaration && !(getModifierFlags(declaration) & ModifierFlags.Static);
798+
return !isDeclarationInstanceProperty || getContainingClass(usage) !== getContainingClass(declaration);
799799
}
800800

801801
current = current.parent;

0 commit comments

Comments
 (0)