diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ed4cd7b03f75a..da6554ea83369 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11360,6 +11360,33 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { !declaration.initializer && (noImplicitAny || isInJSFile(declaration)); } + function isThisPropertyAccessInAutoContainer(node: ElementAccessExpression | PropertyAccessExpression | QualifiedName, prop: Symbol) { + const declaration = Debug.checkDefined(prop.valueDeclaration); + if (hasStaticModifier(declaration)) { + if (!isThisProperty(node) || !isAutoTypedProperty(prop)) { + return false; + } + const autoContainer = getAutoContainer(node)!; + return isClassStaticBlockDeclaration(autoContainer) && (prop.parent && getClassLikeDeclarationOfSymbol(prop.parent)) === autoContainer.parent; + } + if (!isConstructorDeclaredProperty(prop) && (!isThisProperty(node) || !isAutoTypedProperty(prop))) { + return false; + } + const autoContainer = getAutoContainer(node)!; + return isConstructorDeclaration(autoContainer) && (prop.parent && getClassLikeDeclarationOfSymbol(prop.parent)) === autoContainer.parent || autoContainer === getDeclaringConstructor(prop); + } + + function getAutoContainer(node: Node) { + let container = getContainingFunctionOrClassStaticBlock(node); + while (container) { + if (getImmediatelyInvokedFunctionExpression(container)) { + container = getContainingFunctionOrClassStaticBlock(container); + continue; + } + return container; + } + } + function getDeclaringConstructor(symbol: Symbol) { if (!symbol.declarations) { return; @@ -18624,7 +18651,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (accessFlags & AccessFlags.CacheSymbol) { getNodeLinks(accessNode!).resolvedSymbol = prop; } - if (isThisPropertyAccessInConstructor(accessExpression, prop)) { + if (isThisPropertyAccessInDeclaringConstructor(accessExpression, prop)) { return autoType; } } @@ -31602,12 +31629,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case AssignmentDeclarationKind.ThisProperty: const lhsSymbol = getSymbolForExpression(binaryExpression.left); const decl = lhsSymbol && lhsSymbol.valueDeclaration; - // Unannotated, uninitialized property declarations have a type implied by their usage in the constructor. - // We avoid calling back into `getTypeOfExpression` and reentering contextual typing to avoid a bogus circularity error in that case. + // Unannotated, uninitialized property declarations have a type implied by their usage in the constructor or static blocks. + // We avoid calling back into `getTypeOfExpression` and reentering contextual typing to avoid a bogus circularity error in that case when the assignment declaration is in the respective auto container if (decl && (isPropertyDeclaration(decl) || isPropertySignature(decl))) { const overallAnnotation = getEffectiveTypeAnnotationNode(decl); - return (overallAnnotation && instantiateType(getTypeFromTypeNode(overallAnnotation), getSymbolLinks(lhsSymbol).mapper)) || + const type = (overallAnnotation && instantiateType(getTypeFromTypeNode(overallAnnotation), getSymbolLinks(lhsSymbol).mapper)) || (isPropertyDeclaration(decl) ? decl.initializer && getTypeOfExpression(binaryExpression.left) : undefined); + if (type || isAccessExpression(binaryExpression.left) && isThisPropertyAccessInAutoContainer(binaryExpression.left, lhsSymbol)) { + return type; + } } if (kind === AssignmentDeclarationKind.None) { return getTypeOfExpression(binaryExpression.left); @@ -34171,7 +34201,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return false; } - function isThisPropertyAccessInConstructor(node: ElementAccessExpression | PropertyAccessExpression | QualifiedName, prop: Symbol) { + function isThisPropertyAccessInDeclaringConstructor(node: ElementAccessExpression | PropertyAccessExpression | QualifiedName, prop: Symbol) { return (isConstructorDeclaredProperty(prop) || isThisProperty(node) && isAutoTypedProperty(prop)) && getThisContainer(node, /*includeArrowFunctions*/ true, /*includeClassComputedPropertyName*/ false) === getDeclaringConstructor(prop); } @@ -34291,7 +34321,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return errorType; } - propType = isThisPropertyAccessInConstructor(node, prop) ? autoType : writeOnly || isWriteOnlyAccess(node) ? getWriteTypeOfSymbol(prop) : getTypeOfSymbol(prop); + propType = isThisPropertyAccessInDeclaringConstructor(node, prop) ? autoType : writeOnly || isWriteOnlyAccess(node) ? getWriteTypeOfSymbol(prop) : getTypeOfSymbol(prop); } return getFlowTypeOfAccessExpression(node, prop, propType, right, checkMode); diff --git a/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.js b/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.js index 1f0d50879c723..f05d81f3e69fa 100644 --- a/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.js +++ b/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.js @@ -16,6 +16,24 @@ export class Cls { this[0] = [seed]; } } + +export class Cls2 { + accessor x; + accessor y; + accessor z; + + accessor 0; + + constructor(seed: number) { + (() => { + this['x'] = [seed]; + this['y'] = { seed }; + this['z'] = `${seed}`; + + this[0] = [seed]; + })(); + } +} //// [classAccessorInitializationInferenceWithElementAccess1.js] @@ -31,6 +49,20 @@ export class Cls { this[0] = [seed]; } } +export class Cls2 { + accessor x; + accessor y; + accessor z; + accessor 0; + constructor(seed) { + (() => { + this['x'] = [seed]; + this['y'] = { seed }; + this['z'] = `${seed}`; + this[0] = [seed]; + })(); + } +} //// [classAccessorInitializationInferenceWithElementAccess1.d.ts] @@ -43,3 +75,12 @@ export declare class Cls { accessor 0: number[]; constructor(seed: number); } +export declare class Cls2 { + accessor x: number[]; + accessor y: { + seed: number; + }; + accessor z: string; + accessor 0: number[]; + constructor(seed: number); +} diff --git a/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.symbols b/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.symbols index 4f328fa9da5b3..7868d54e7f655 100644 --- a/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.symbols +++ b/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.symbols @@ -41,3 +41,46 @@ export class Cls { } } +export class Cls2 { +>Cls2 : Symbol(Cls2, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 14, 1)) + + accessor x; +>x : Symbol(Cls2.x, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 16, 19)) + + accessor y; +>y : Symbol(Cls2.y, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 17, 15)) + + accessor z; +>z : Symbol(Cls2.z, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 18, 15)) + + accessor 0; +>0 : Symbol(Cls2[0], Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 19, 15)) + + constructor(seed: number) { +>seed : Symbol(seed, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 23, 16)) + + (() => { + this['x'] = [seed]; +>this : Symbol(Cls2, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 14, 1)) +>'x' : Symbol(Cls2.x, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 16, 19)) +>seed : Symbol(seed, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 23, 16)) + + this['y'] = { seed }; +>this : Symbol(Cls2, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 14, 1)) +>'y' : Symbol(Cls2.y, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 17, 15)) +>seed : Symbol(seed, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 26, 25)) + + this['z'] = `${seed}`; +>this : Symbol(Cls2, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 14, 1)) +>'z' : Symbol(Cls2.z, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 18, 15)) +>seed : Symbol(seed, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 23, 16)) + + this[0] = [seed]; +>this : Symbol(Cls2, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 14, 1)) +>0 : Symbol(Cls2[0], Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 19, 15)) +>seed : Symbol(seed, Decl(classAccessorInitializationInferenceWithElementAccess1.ts, 23, 16)) + + })(); + } +} + diff --git a/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.types b/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.types index 63ed461d086ca..ac73cecc6b101 100644 --- a/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.types +++ b/tests/baselines/reference/classAccessorInitializationInferenceWithElementAccess1.types @@ -83,3 +83,95 @@ export class Cls { } } +export class Cls2 { +>Cls2 : Cls2 +> : ^^^^ + + accessor x; +>x : number[] +> : ^^^^^^^^ + + accessor y; +>y : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ + + accessor z; +>z : string +> : ^^^^^^ + + accessor 0; +>0 : number[] +> : ^^^^^^^^ + + constructor(seed: number) { +>seed : number +> : ^^^^^^ + + (() => { +>(() => { this['x'] = [seed]; this['y'] = { seed }; this['z'] = `${seed}`; this[0] = [seed]; })() : void +> : ^^^^ +>(() => { this['x'] = [seed]; this['y'] = { seed }; this['z'] = `${seed}`; this[0] = [seed]; }) : () => void +> : ^^^^^^^^^^ +>() => { this['x'] = [seed]; this['y'] = { seed }; this['z'] = `${seed}`; this[0] = [seed]; } : () => void +> : ^^^^^^^^^^ + + this['x'] = [seed]; +>this['x'] = [seed] : number[] +> : ^^^^^^^^ +>this['x'] : number[] +> : ^^^^^^^^ +>this : this +> : ^^^^ +>'x' : "x" +> : ^^^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + + this['y'] = { seed }; +>this['y'] = { seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this['y'] : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this : this +> : ^^^^ +>'y' : "y" +> : ^^^ +>{ seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>seed : number +> : ^^^^^^ + + this['z'] = `${seed}`; +>this['z'] = `${seed}` : string +> : ^^^^^^ +>this['z'] : string +> : ^^^^^^ +>this : this +> : ^^^^ +>'z' : "z" +> : ^^^ +>`${seed}` : string +> : ^^^^^^ +>seed : number +> : ^^^^^^ + + this[0] = [seed]; +>this[0] = [seed] : number[] +> : ^^^^^^^^ +>this[0] : number[] +> : ^^^^^^^^ +>this : this +> : ^^^^ +>0 : 0 +> : ^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + + })(); + } +} + diff --git a/tests/baselines/reference/classAttributeInferenceContextualTypingOutsideOfConstructor1.errors.txt b/tests/baselines/reference/classAttributeInferenceContextualTypingOutsideOfConstructor1.errors.txt new file mode 100644 index 0000000000000..f1ea3b9565779 --- /dev/null +++ b/tests/baselines/reference/classAttributeInferenceContextualTypingOutsideOfConstructor1.errors.txt @@ -0,0 +1,61 @@ +classAttributeInferenceContextualTypingOutsideOfConstructor1.ts(15,22): error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +classAttributeInferenceContextualTypingOutsideOfConstructor1.ts(21,20): error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +classAttributeInferenceContextualTypingOutsideOfConstructor1.ts(33,22): error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +classAttributeInferenceContextualTypingOutsideOfConstructor1.ts(39,20): error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? + + +==== classAttributeInferenceContextualTypingOutsideOfConstructor1.ts (4 errors) ==== + // https://github.com/microsoft/TypeScript/issues/60394 + + type State = { type: "running"; speed: number } | { type: "stopped" }; + + declare const initialState: State; + + class Actor1 { + private state; + + constructor() { + this.state = initialState; + + const localRun = (speed: number) => { + this.state = { type: "running", speed }; + this.state = { type: "runnnning", speed }; // error + ~~~~ +!!! error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +!!! related TS6500 classAttributeInferenceContextualTypingOutsideOfConstructor1.ts:3:16: The expected type comes from property 'type' which is declared here on type 'State' + } + } + + run(speed: number) { + this.state = { type: "running", speed }; + this.state = { type: "runnnning", speed }; // error + ~~~~ +!!! error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +!!! related TS6500 classAttributeInferenceContextualTypingOutsideOfConstructor1.ts:3:16: The expected type comes from property 'type' which is declared here on type 'State' + } + } + + class Actor2 { + accessor state; + + constructor() { + this.state = initialState; + + const localRun = (speed: number) => { + this.state = { type: "running", speed }; + this.state = { type: "runnnning", speed }; // error + ~~~~ +!!! error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +!!! related TS6500 classAttributeInferenceContextualTypingOutsideOfConstructor1.ts:3:16: The expected type comes from property 'type' which is declared here on type 'State' + } + } + + run(speed: number) { + this.state = { type: "running", speed }; + this.state = { type: "runnnning", speed }; // error + ~~~~ +!!! error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +!!! related TS6500 classAttributeInferenceContextualTypingOutsideOfConstructor1.ts:3:16: The expected type comes from property 'type' which is declared here on type 'State' + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classAttributeInferenceContextualTypingOutsideOfConstructor1.symbols b/tests/baselines/reference/classAttributeInferenceContextualTypingOutsideOfConstructor1.symbols new file mode 100644 index 0000000000000..85383243a00ff --- /dev/null +++ b/tests/baselines/reference/classAttributeInferenceContextualTypingOutsideOfConstructor1.symbols @@ -0,0 +1,121 @@ +//// [tests/cases/compiler/classAttributeInferenceContextualTypingOutsideOfConstructor1.ts] //// + +=== classAttributeInferenceContextualTypingOutsideOfConstructor1.ts === +// https://github.com/microsoft/TypeScript/issues/60394 + +type State = { type: "running"; speed: number } | { type: "stopped" }; +>State : Symbol(State, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 0, 0)) +>type : Symbol(type, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 2, 14)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 2, 31)) +>type : Symbol(type, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 2, 51)) + +declare const initialState: State; +>initialState : Symbol(initialState, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 4, 13)) +>State : Symbol(State, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 0, 0)) + +class Actor1 { +>Actor1 : Symbol(Actor1, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 4, 34)) + + private state; +>state : Symbol(Actor1.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 6, 14)) + + constructor() { + this.state = initialState; +>this.state : Symbol(Actor1.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 6, 14)) +>this : Symbol(Actor1, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 4, 34)) +>state : Symbol(Actor1.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 6, 14)) +>initialState : Symbol(initialState, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 4, 13)) + + const localRun = (speed: number) => { +>localRun : Symbol(localRun, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 12, 9)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 12, 22)) + + this.state = { type: "running", speed }; +>this.state : Symbol(Actor1.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 6, 14)) +>this : Symbol(Actor1, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 4, 34)) +>state : Symbol(Actor1.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 6, 14)) +>type : Symbol(type, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 13, 20)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 13, 37)) + + this.state = { type: "runnnning", speed }; // error +>this.state : Symbol(Actor1.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 6, 14)) +>this : Symbol(Actor1, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 4, 34)) +>state : Symbol(Actor1.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 6, 14)) +>type : Symbol(type, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 14, 20)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 14, 39)) + } + } + + run(speed: number) { +>run : Symbol(Actor1.run, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 16, 3)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 18, 6)) + + this.state = { type: "running", speed }; +>this.state : Symbol(Actor1.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 6, 14)) +>this : Symbol(Actor1, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 4, 34)) +>state : Symbol(Actor1.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 6, 14)) +>type : Symbol(type, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 19, 18)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 19, 35)) + + this.state = { type: "runnnning", speed }; // error +>this.state : Symbol(Actor1.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 6, 14)) +>this : Symbol(Actor1, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 4, 34)) +>state : Symbol(Actor1.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 6, 14)) +>type : Symbol(type, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 20, 18)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 20, 37)) + } +} + +class Actor2 { +>Actor2 : Symbol(Actor2, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 22, 1)) + + accessor state; +>state : Symbol(Actor2.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 24, 14)) + + constructor() { + this.state = initialState; +>this.state : Symbol(Actor2.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 24, 14)) +>this : Symbol(Actor2, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 22, 1)) +>state : Symbol(Actor2.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 24, 14)) +>initialState : Symbol(initialState, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 4, 13)) + + const localRun = (speed: number) => { +>localRun : Symbol(localRun, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 30, 9)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 30, 22)) + + this.state = { type: "running", speed }; +>this.state : Symbol(Actor2.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 24, 14)) +>this : Symbol(Actor2, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 22, 1)) +>state : Symbol(Actor2.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 24, 14)) +>type : Symbol(type, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 31, 20)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 31, 37)) + + this.state = { type: "runnnning", speed }; // error +>this.state : Symbol(Actor2.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 24, 14)) +>this : Symbol(Actor2, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 22, 1)) +>state : Symbol(Actor2.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 24, 14)) +>type : Symbol(type, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 32, 20)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 32, 39)) + } + } + + run(speed: number) { +>run : Symbol(Actor2.run, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 34, 3)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 36, 6)) + + this.state = { type: "running", speed }; +>this.state : Symbol(Actor2.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 24, 14)) +>this : Symbol(Actor2, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 22, 1)) +>state : Symbol(Actor2.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 24, 14)) +>type : Symbol(type, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 37, 18)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 37, 35)) + + this.state = { type: "runnnning", speed }; // error +>this.state : Symbol(Actor2.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 24, 14)) +>this : Symbol(Actor2, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 22, 1)) +>state : Symbol(Actor2.state, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 24, 14)) +>type : Symbol(type, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 38, 18)) +>speed : Symbol(speed, Decl(classAttributeInferenceContextualTypingOutsideOfConstructor1.ts, 38, 37)) + } +} + diff --git a/tests/baselines/reference/classAttributeInferenceContextualTypingOutsideOfConstructor1.types b/tests/baselines/reference/classAttributeInferenceContextualTypingOutsideOfConstructor1.types new file mode 100644 index 0000000000000..8550cde340dd3 --- /dev/null +++ b/tests/baselines/reference/classAttributeInferenceContextualTypingOutsideOfConstructor1.types @@ -0,0 +1,241 @@ +//// [tests/cases/compiler/classAttributeInferenceContextualTypingOutsideOfConstructor1.ts] //// + +=== classAttributeInferenceContextualTypingOutsideOfConstructor1.ts === +// https://github.com/microsoft/TypeScript/issues/60394 + +type State = { type: "running"; speed: number } | { type: "stopped" }; +>State : State +> : ^^^^^ +>type : "running" +> : ^^^^^^^^^ +>speed : number +> : ^^^^^^ +>type : "stopped" +> : ^^^^^^^^^ + +declare const initialState: State; +>initialState : State +> : ^^^^^ + +class Actor1 { +>Actor1 : Actor1 +> : ^^^^^^ + + private state; +>state : State +> : ^^^^^ + + constructor() { + this.state = initialState; +>this.state = initialState : State +> : ^^^^^ +>this.state : State +> : ^^^^^ +>this : this +> : ^^^^ +>state : State +> : ^^^^^ +>initialState : State +> : ^^^^^ + + const localRun = (speed: number) => { +>localRun : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>(speed: number) => { this.state = { type: "running", speed }; this.state = { type: "runnnning", speed }; // error } : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.state = { type: "running", speed }; +>this.state = { type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.state : State +> : ^^^^^ +>this : this +> : ^^^^ +>state : State +> : ^^^^^ +>{ type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "running" +> : ^^^^^^^^^ +>"running" : "running" +> : ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.state = { type: "runnnning", speed }; // error +>this.state = { type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.state : State +> : ^^^^^ +>this : this +> : ^^^^ +>state : State +> : ^^^^^ +>{ type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "runnnning" +> : ^^^^^^^^^^^ +>"runnnning" : "runnnning" +> : ^^^^^^^^^^^ +>speed : number +> : ^^^^^^ + } + } + + run(speed: number) { +>run : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.state = { type: "running", speed }; +>this.state = { type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.state : State +> : ^^^^^ +>this : this +> : ^^^^ +>state : State +> : ^^^^^ +>{ type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "running" +> : ^^^^^^^^^ +>"running" : "running" +> : ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.state = { type: "runnnning", speed }; // error +>this.state = { type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.state : State +> : ^^^^^ +>this : this +> : ^^^^ +>state : State +> : ^^^^^ +>{ type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "runnnning" +> : ^^^^^^^^^^^ +>"runnnning" : "runnnning" +> : ^^^^^^^^^^^ +>speed : number +> : ^^^^^^ + } +} + +class Actor2 { +>Actor2 : Actor2 +> : ^^^^^^ + + accessor state; +>state : State +> : ^^^^^ + + constructor() { + this.state = initialState; +>this.state = initialState : State +> : ^^^^^ +>this.state : State +> : ^^^^^ +>this : this +> : ^^^^ +>state : State +> : ^^^^^ +>initialState : State +> : ^^^^^ + + const localRun = (speed: number) => { +>localRun : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>(speed: number) => { this.state = { type: "running", speed }; this.state = { type: "runnnning", speed }; // error } : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.state = { type: "running", speed }; +>this.state = { type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.state : State +> : ^^^^^ +>this : this +> : ^^^^ +>state : State +> : ^^^^^ +>{ type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "running" +> : ^^^^^^^^^ +>"running" : "running" +> : ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.state = { type: "runnnning", speed }; // error +>this.state = { type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.state : State +> : ^^^^^ +>this : this +> : ^^^^ +>state : State +> : ^^^^^ +>{ type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "runnnning" +> : ^^^^^^^^^^^ +>"runnnning" : "runnnning" +> : ^^^^^^^^^^^ +>speed : number +> : ^^^^^^ + } + } + + run(speed: number) { +>run : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.state = { type: "running", speed }; +>this.state = { type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.state : State +> : ^^^^^ +>this : this +> : ^^^^ +>state : State +> : ^^^^^ +>{ type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "running" +> : ^^^^^^^^^ +>"running" : "running" +> : ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.state = { type: "runnnning", speed }; // error +>this.state = { type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.state : State +> : ^^^^^ +>this : this +> : ^^^^ +>state : State +> : ^^^^^ +>{ type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "runnnning" +> : ^^^^^^^^^^^ +>"runnnning" : "runnnning" +> : ^^^^^^^^^^^ +>speed : number +> : ^^^^^^ + } +} + diff --git a/tests/baselines/reference/classAttributeInferenceTemplate.js b/tests/baselines/reference/classAttributeInferenceTemplate.js index 60da0b173d391..4bb3b504f4dd0 100644 --- a/tests/baselines/reference/classAttributeInferenceTemplate.js +++ b/tests/baselines/reference/classAttributeInferenceTemplate.js @@ -8,10 +8,10 @@ class MyClass { constructor() { const variable = 'something' - this.property = `foo`; // Correctly inferred as `string` - this.property2 = `foo-${variable}`; // Causes an error + this.property = `foo`; + this.property2 = `foo-${variable}`; - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; } } @@ -22,10 +22,42 @@ class MyClass2 { constructor() { const variable = 'something' - this.property = `foo`; // Correctly inferred as `string` - this.property2 = `foo-${variable}`; // Causes an error + this.property = `foo`; + this.property2 = `foo-${variable}`; - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; + } +} + +class MyClass3 { + property; + property2; + + constructor() { + (() => { + const variable = 'something' + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + })(); + } +} + +class MyClass4 { + accessor property; + accessor property2; + + constructor() { + (() => { + const variable = 'something' + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + })(); } } @@ -37,9 +69,9 @@ class MyClass { property2; constructor() { const variable = 'something'; - this.property = `foo`; // Correctly inferred as `string` - this.property2 = `foo-${variable}`; // Causes an error - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + this.property = `foo`; + this.property2 = `foo-${variable}`; + const localProperty = `foo-${variable}`; } } class MyClass2 { @@ -47,8 +79,32 @@ class MyClass2 { accessor property2; constructor() { const variable = 'something'; - this.property = `foo`; // Correctly inferred as `string` - this.property2 = `foo-${variable}`; // Causes an error - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + this.property = `foo`; + this.property2 = `foo-${variable}`; + const localProperty = `foo-${variable}`; + } +} +class MyClass3 { + property; + property2; + constructor() { + (() => { + const variable = 'something'; + this.property = `foo`; + this.property2 = `foo-${variable}`; + const localProperty = `foo-${variable}`; + })(); + } +} +class MyClass4 { + accessor property; + accessor property2; + constructor() { + (() => { + const variable = 'something'; + this.property = `foo`; + this.property2 = `foo-${variable}`; + const localProperty = `foo-${variable}`; + })(); } } diff --git a/tests/baselines/reference/classAttributeInferenceTemplate.symbols b/tests/baselines/reference/classAttributeInferenceTemplate.symbols index a5b2df3334bfc..ed05b243c7e74 100644 --- a/tests/baselines/reference/classAttributeInferenceTemplate.symbols +++ b/tests/baselines/reference/classAttributeInferenceTemplate.symbols @@ -14,18 +14,18 @@ class MyClass { const variable = 'something' >variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 5, 13)) - this.property = `foo`; // Correctly inferred as `string` + this.property = `foo`; >this.property : Symbol(MyClass.property, Decl(classAttributeInferenceTemplate.ts, 0, 15)) >this : Symbol(MyClass, Decl(classAttributeInferenceTemplate.ts, 0, 0)) >property : Symbol(MyClass.property, Decl(classAttributeInferenceTemplate.ts, 0, 15)) - this.property2 = `foo-${variable}`; // Causes an error + this.property2 = `foo-${variable}`; >this.property2 : Symbol(MyClass.property2, Decl(classAttributeInferenceTemplate.ts, 1, 13)) >this : Symbol(MyClass, Decl(classAttributeInferenceTemplate.ts, 0, 0)) >property2 : Symbol(MyClass.property2, Decl(classAttributeInferenceTemplate.ts, 1, 13)) >variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 5, 13)) - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; >localProperty : Symbol(localProperty, Decl(classAttributeInferenceTemplate.ts, 10, 13)) >variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 5, 13)) } @@ -44,20 +44,86 @@ class MyClass2 { const variable = 'something' >variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 19, 13)) - this.property = `foo`; // Correctly inferred as `string` + this.property = `foo`; >this.property : Symbol(MyClass2.property, Decl(classAttributeInferenceTemplate.ts, 14, 16)) >this : Symbol(MyClass2, Decl(classAttributeInferenceTemplate.ts, 12, 1)) >property : Symbol(MyClass2.property, Decl(classAttributeInferenceTemplate.ts, 14, 16)) - this.property2 = `foo-${variable}`; // Causes an error + this.property2 = `foo-${variable}`; >this.property2 : Symbol(MyClass2.property2, Decl(classAttributeInferenceTemplate.ts, 15, 22)) >this : Symbol(MyClass2, Decl(classAttributeInferenceTemplate.ts, 12, 1)) >property2 : Symbol(MyClass2.property2, Decl(classAttributeInferenceTemplate.ts, 15, 22)) >variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 19, 13)) - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; >localProperty : Symbol(localProperty, Decl(classAttributeInferenceTemplate.ts, 24, 13)) >variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 19, 13)) } } +class MyClass3 { +>MyClass3 : Symbol(MyClass3, Decl(classAttributeInferenceTemplate.ts, 26, 1)) + + property; +>property : Symbol(MyClass3.property, Decl(classAttributeInferenceTemplate.ts, 28, 16)) + + property2; +>property2 : Symbol(MyClass3.property2, Decl(classAttributeInferenceTemplate.ts, 29, 13)) + + constructor() { + (() => { + const variable = 'something' +>variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 34, 17)) + + this.property = `foo`; +>this.property : Symbol(MyClass3.property, Decl(classAttributeInferenceTemplate.ts, 28, 16)) +>this : Symbol(MyClass3, Decl(classAttributeInferenceTemplate.ts, 26, 1)) +>property : Symbol(MyClass3.property, Decl(classAttributeInferenceTemplate.ts, 28, 16)) + + this.property2 = `foo-${variable}`; +>this.property2 : Symbol(MyClass3.property2, Decl(classAttributeInferenceTemplate.ts, 29, 13)) +>this : Symbol(MyClass3, Decl(classAttributeInferenceTemplate.ts, 26, 1)) +>property2 : Symbol(MyClass3.property2, Decl(classAttributeInferenceTemplate.ts, 29, 13)) +>variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 34, 17)) + + const localProperty = `foo-${variable}`; +>localProperty : Symbol(localProperty, Decl(classAttributeInferenceTemplate.ts, 39, 17)) +>variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 34, 17)) + + })(); + } +} + +class MyClass4 { +>MyClass4 : Symbol(MyClass4, Decl(classAttributeInferenceTemplate.ts, 42, 1)) + + accessor property; +>property : Symbol(MyClass4.property, Decl(classAttributeInferenceTemplate.ts, 44, 16)) + + accessor property2; +>property2 : Symbol(MyClass4.property2, Decl(classAttributeInferenceTemplate.ts, 45, 22)) + + constructor() { + (() => { + const variable = 'something' +>variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 50, 17)) + + this.property = `foo`; +>this.property : Symbol(MyClass4.property, Decl(classAttributeInferenceTemplate.ts, 44, 16)) +>this : Symbol(MyClass4, Decl(classAttributeInferenceTemplate.ts, 42, 1)) +>property : Symbol(MyClass4.property, Decl(classAttributeInferenceTemplate.ts, 44, 16)) + + this.property2 = `foo-${variable}`; +>this.property2 : Symbol(MyClass4.property2, Decl(classAttributeInferenceTemplate.ts, 45, 22)) +>this : Symbol(MyClass4, Decl(classAttributeInferenceTemplate.ts, 42, 1)) +>property2 : Symbol(MyClass4.property2, Decl(classAttributeInferenceTemplate.ts, 45, 22)) +>variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 50, 17)) + + const localProperty = `foo-${variable}`; +>localProperty : Symbol(localProperty, Decl(classAttributeInferenceTemplate.ts, 55, 17)) +>variable : Symbol(variable, Decl(classAttributeInferenceTemplate.ts, 50, 17)) + + })(); + } +} + diff --git a/tests/baselines/reference/classAttributeInferenceTemplate.types b/tests/baselines/reference/classAttributeInferenceTemplate.types index 1386ee62d417a..1c669f8f23eff 100644 --- a/tests/baselines/reference/classAttributeInferenceTemplate.types +++ b/tests/baselines/reference/classAttributeInferenceTemplate.types @@ -20,7 +20,7 @@ class MyClass { >'something' : "something" > : ^^^^^^^^^^^ - this.property = `foo`; // Correctly inferred as `string` + this.property = `foo`; >this.property = `foo` : "foo" > : ^^^^^ >this.property : string @@ -32,7 +32,7 @@ class MyClass { >`foo` : "foo" > : ^^^^^ - this.property2 = `foo-${variable}`; // Causes an error + this.property2 = `foo-${variable}`; >this.property2 = `foo-${variable}` : "foo-something" > : ^^^^^^^^^^^^^^^ >this.property2 : string @@ -46,7 +46,7 @@ class MyClass { >variable : "something" > : ^^^^^^^^^^^ - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; >localProperty : "foo-something" > : ^^^^^^^^^^^^^^^ >`foo-${variable}` : "foo-something" @@ -75,7 +75,7 @@ class MyClass2 { >'something' : "something" > : ^^^^^^^^^^^ - this.property = `foo`; // Correctly inferred as `string` + this.property = `foo`; >this.property = `foo` : "foo" > : ^^^^^ >this.property : string @@ -87,7 +87,7 @@ class MyClass2 { >`foo` : "foo" > : ^^^^^ - this.property2 = `foo-${variable}`; // Causes an error + this.property2 = `foo-${variable}`; >this.property2 = `foo-${variable}` : "foo-something" > : ^^^^^^^^^^^^^^^ >this.property2 : string @@ -101,7 +101,7 @@ class MyClass2 { >variable : "something" > : ^^^^^^^^^^^ - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; >localProperty : "foo-something" > : ^^^^^^^^^^^^^^^ >`foo-${variable}` : "foo-something" @@ -111,3 +111,133 @@ class MyClass2 { } } +class MyClass3 { +>MyClass3 : MyClass3 +> : ^^^^^^^^ + + property; +>property : string +> : ^^^^^^ + + property2; +>property2 : string +> : ^^^^^^ + + constructor() { + (() => { +>(() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; })() : void +> : ^^^^ +>(() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; }) : () => void +> : ^^^^^^^^^^ +>() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; } : () => void +> : ^^^^^^^^^^ + + const variable = 'something' +>variable : "something" +> : ^^^^^^^^^^^ +>'something' : "something" +> : ^^^^^^^^^^^ + + this.property = `foo`; +>this.property = `foo` : "foo" +> : ^^^^^ +>this.property : string +> : ^^^^^^ +>this : this +> : ^^^^ +>property : string +> : ^^^^^^ +>`foo` : "foo" +> : ^^^^^ + + this.property2 = `foo-${variable}`; +>this.property2 = `foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>this.property2 : string +> : ^^^^^^ +>this : this +> : ^^^^ +>property2 : string +> : ^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + const localProperty = `foo-${variable}`; +>localProperty : "foo-something" +> : ^^^^^^^^^^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + })(); + } +} + +class MyClass4 { +>MyClass4 : MyClass4 +> : ^^^^^^^^ + + accessor property; +>property : string +> : ^^^^^^ + + accessor property2; +>property2 : string +> : ^^^^^^ + + constructor() { + (() => { +>(() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; })() : void +> : ^^^^ +>(() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; }) : () => void +> : ^^^^^^^^^^ +>() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; } : () => void +> : ^^^^^^^^^^ + + const variable = 'something' +>variable : "something" +> : ^^^^^^^^^^^ +>'something' : "something" +> : ^^^^^^^^^^^ + + this.property = `foo`; +>this.property = `foo` : "foo" +> : ^^^^^ +>this.property : string +> : ^^^^^^ +>this : this +> : ^^^^ +>property : string +> : ^^^^^^ +>`foo` : "foo" +> : ^^^^^ + + this.property2 = `foo-${variable}`; +>this.property2 = `foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>this.property2 : string +> : ^^^^^^ +>this : this +> : ^^^^ +>property2 : string +> : ^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + const localProperty = `foo-${variable}`; +>localProperty : "foo-something" +> : ^^^^^^^^^^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + })(); + } +} + diff --git a/tests/baselines/reference/classAttributeInferenceTemplateJS.symbols b/tests/baselines/reference/classAttributeInferenceTemplateJS.symbols index 96e45c51a750a..39e68b9393207 100644 --- a/tests/baselines/reference/classAttributeInferenceTemplateJS.symbols +++ b/tests/baselines/reference/classAttributeInferenceTemplateJS.symbols @@ -14,18 +14,18 @@ class MyClass { const variable = 'something' >variable : Symbol(variable, Decl(index.js, 5, 13)) - this.property = `foo`; // Correctly inferred as `string` + this.property = `foo`; >this.property : Symbol(MyClass.property, Decl(index.js, 0, 15)) >this : Symbol(MyClass, Decl(index.js, 0, 0)) >property : Symbol(MyClass.property, Decl(index.js, 0, 15)) - this.property2 = `foo-${variable}`; // Causes an error + this.property2 = `foo-${variable}`; >this.property2 : Symbol(MyClass.property2, Decl(index.js, 1, 13)) >this : Symbol(MyClass, Decl(index.js, 0, 0)) >property2 : Symbol(MyClass.property2, Decl(index.js, 1, 13)) >variable : Symbol(variable, Decl(index.js, 5, 13)) - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; >localProperty : Symbol(localProperty, Decl(index.js, 10, 13)) >variable : Symbol(variable, Decl(index.js, 5, 13)) } @@ -44,20 +44,86 @@ class MyClass2 { const variable = 'something' >variable : Symbol(variable, Decl(index.js, 19, 13)) - this.property = `foo`; // Correctly inferred as `string` + this.property = `foo`; >this.property : Symbol(MyClass2.property, Decl(index.js, 14, 16)) >this : Symbol(MyClass2, Decl(index.js, 12, 1)) >property : Symbol(MyClass2.property, Decl(index.js, 14, 16)) - this.property2 = `foo-${variable}`; // Causes an error + this.property2 = `foo-${variable}`; >this.property2 : Symbol(MyClass2.property2, Decl(index.js, 15, 22)) >this : Symbol(MyClass2, Decl(index.js, 12, 1)) >property2 : Symbol(MyClass2.property2, Decl(index.js, 15, 22)) >variable : Symbol(variable, Decl(index.js, 19, 13)) - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; >localProperty : Symbol(localProperty, Decl(index.js, 24, 13)) >variable : Symbol(variable, Decl(index.js, 19, 13)) } } +class MyClass3 { +>MyClass3 : Symbol(MyClass3, Decl(index.js, 26, 1)) + + property; +>property : Symbol(MyClass3.property, Decl(index.js, 28, 16)) + + property2; +>property2 : Symbol(MyClass3.property2, Decl(index.js, 29, 13)) + + constructor() { + (() => { + const variable = 'something' +>variable : Symbol(variable, Decl(index.js, 34, 17)) + + this.property = `foo`; +>this.property : Symbol(MyClass3.property, Decl(index.js, 28, 16)) +>this : Symbol(MyClass3, Decl(index.js, 26, 1)) +>property : Symbol(MyClass3.property, Decl(index.js, 28, 16)) + + this.property2 = `foo-${variable}`; +>this.property2 : Symbol(MyClass3.property2, Decl(index.js, 29, 13)) +>this : Symbol(MyClass3, Decl(index.js, 26, 1)) +>property2 : Symbol(MyClass3.property2, Decl(index.js, 29, 13)) +>variable : Symbol(variable, Decl(index.js, 34, 17)) + + const localProperty = `foo-${variable}`; +>localProperty : Symbol(localProperty, Decl(index.js, 39, 17)) +>variable : Symbol(variable, Decl(index.js, 34, 17)) + + })(); + } +} + +class MyClass4 { +>MyClass4 : Symbol(MyClass4, Decl(index.js, 42, 1)) + + accessor property; +>property : Symbol(MyClass4.property, Decl(index.js, 44, 16)) + + accessor property2; +>property2 : Symbol(MyClass4.property2, Decl(index.js, 45, 22)) + + constructor() { + (() => { + const variable = 'something' +>variable : Symbol(variable, Decl(index.js, 50, 17)) + + this.property = `foo`; +>this.property : Symbol(MyClass4.property, Decl(index.js, 44, 16)) +>this : Symbol(MyClass4, Decl(index.js, 42, 1)) +>property : Symbol(MyClass4.property, Decl(index.js, 44, 16)) + + this.property2 = `foo-${variable}`; +>this.property2 : Symbol(MyClass4.property2, Decl(index.js, 45, 22)) +>this : Symbol(MyClass4, Decl(index.js, 42, 1)) +>property2 : Symbol(MyClass4.property2, Decl(index.js, 45, 22)) +>variable : Symbol(variable, Decl(index.js, 50, 17)) + + const localProperty = `foo-${variable}`; +>localProperty : Symbol(localProperty, Decl(index.js, 55, 17)) +>variable : Symbol(variable, Decl(index.js, 50, 17)) + + })(); + } +} + diff --git a/tests/baselines/reference/classAttributeInferenceTemplateJS.types b/tests/baselines/reference/classAttributeInferenceTemplateJS.types index 74d16a8c1409d..87669c92ec5a8 100644 --- a/tests/baselines/reference/classAttributeInferenceTemplateJS.types +++ b/tests/baselines/reference/classAttributeInferenceTemplateJS.types @@ -20,7 +20,7 @@ class MyClass { >'something' : "something" > : ^^^^^^^^^^^ - this.property = `foo`; // Correctly inferred as `string` + this.property = `foo`; >this.property = `foo` : "foo" > : ^^^^^ >this.property : string @@ -32,7 +32,7 @@ class MyClass { >`foo` : "foo" > : ^^^^^ - this.property2 = `foo-${variable}`; // Causes an error + this.property2 = `foo-${variable}`; >this.property2 = `foo-${variable}` : "foo-something" > : ^^^^^^^^^^^^^^^ >this.property2 : string @@ -46,7 +46,7 @@ class MyClass { >variable : "something" > : ^^^^^^^^^^^ - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; >localProperty : "foo-something" > : ^^^^^^^^^^^^^^^ >`foo-${variable}` : "foo-something" @@ -75,7 +75,7 @@ class MyClass2 { >'something' : "something" > : ^^^^^^^^^^^ - this.property = `foo`; // Correctly inferred as `string` + this.property = `foo`; >this.property = `foo` : "foo" > : ^^^^^ >this.property : string @@ -87,7 +87,7 @@ class MyClass2 { >`foo` : "foo" > : ^^^^^ - this.property2 = `foo-${variable}`; // Causes an error + this.property2 = `foo-${variable}`; >this.property2 = `foo-${variable}` : "foo-something" > : ^^^^^^^^^^^^^^^ >this.property2 : string @@ -101,7 +101,7 @@ class MyClass2 { >variable : "something" > : ^^^^^^^^^^^ - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; >localProperty : "foo-something" > : ^^^^^^^^^^^^^^^ >`foo-${variable}` : "foo-something" @@ -111,3 +111,133 @@ class MyClass2 { } } +class MyClass3 { +>MyClass3 : MyClass3 +> : ^^^^^^^^ + + property; +>property : string +> : ^^^^^^ + + property2; +>property2 : string +> : ^^^^^^ + + constructor() { + (() => { +>(() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; })() : void +> : ^^^^ +>(() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; }) : () => void +> : ^^^^^^^^^^ +>() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; } : () => void +> : ^^^^^^^^^^ + + const variable = 'something' +>variable : "something" +> : ^^^^^^^^^^^ +>'something' : "something" +> : ^^^^^^^^^^^ + + this.property = `foo`; +>this.property = `foo` : "foo" +> : ^^^^^ +>this.property : string +> : ^^^^^^ +>this : this +> : ^^^^ +>property : string +> : ^^^^^^ +>`foo` : "foo" +> : ^^^^^ + + this.property2 = `foo-${variable}`; +>this.property2 = `foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>this.property2 : string +> : ^^^^^^ +>this : this +> : ^^^^ +>property2 : string +> : ^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + const localProperty = `foo-${variable}`; +>localProperty : "foo-something" +> : ^^^^^^^^^^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + })(); + } +} + +class MyClass4 { +>MyClass4 : MyClass4 +> : ^^^^^^^^ + + accessor property; +>property : string +> : ^^^^^^ + + accessor property2; +>property2 : string +> : ^^^^^^ + + constructor() { + (() => { +>(() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; })() : void +> : ^^^^ +>(() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; }) : () => void +> : ^^^^^^^^^^ +>() => { const variable = 'something' this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; } : () => void +> : ^^^^^^^^^^ + + const variable = 'something' +>variable : "something" +> : ^^^^^^^^^^^ +>'something' : "something" +> : ^^^^^^^^^^^ + + this.property = `foo`; +>this.property = `foo` : "foo" +> : ^^^^^ +>this.property : string +> : ^^^^^^ +>this : this +> : ^^^^ +>property : string +> : ^^^^^^ +>`foo` : "foo" +> : ^^^^^ + + this.property2 = `foo-${variable}`; +>this.property2 = `foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>this.property2 : string +> : ^^^^^^ +>this : this +> : ^^^^ +>property2 : string +> : ^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + const localProperty = `foo-${variable}`; +>localProperty : "foo-something" +> : ^^^^^^^^^^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + })(); + } +} + diff --git a/tests/baselines/reference/classAttributeInferenceUncheckedJs1.symbols b/tests/baselines/reference/classAttributeInferenceUncheckedJs1.symbols new file mode 100644 index 0000000000000..79fa1efb0466c --- /dev/null +++ b/tests/baselines/reference/classAttributeInferenceUncheckedJs1.symbols @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/classAttributeInferenceUncheckedJs1.ts] //// + +=== classAttributeInferenceUncheckedJs1.js === +class C1 { +>C1 : Symbol(C1, Decl(classAttributeInferenceUncheckedJs1.js, 0, 0)) + + bar; +>bar : Symbol(C1.bar, Decl(classAttributeInferenceUncheckedJs1.js, 0, 10)) + + constructor () { + this.foo; +>this : Symbol(C1, Decl(classAttributeInferenceUncheckedJs1.js, 0, 0)) + + this.bar; +>this.bar : Symbol(C1.bar, Decl(classAttributeInferenceUncheckedJs1.js, 0, 10)) +>this : Symbol(C1, Decl(classAttributeInferenceUncheckedJs1.js, 0, 0)) +>bar : Symbol(C1.bar, Decl(classAttributeInferenceUncheckedJs1.js, 0, 10)) + } +} + +class C2 { +>C2 : Symbol(C2, Decl(classAttributeInferenceUncheckedJs1.js, 6, 1)) + + #bar; +>#bar : Symbol(C2.#bar, Decl(classAttributeInferenceUncheckedJs1.js, 8, 10)) + + constructor () { + this.#foo; +>this : Symbol(C2, Decl(classAttributeInferenceUncheckedJs1.js, 6, 1)) + + this.#bar; +>this.#bar : Symbol(C2.#bar, Decl(classAttributeInferenceUncheckedJs1.js, 8, 10)) +>this : Symbol(C2, Decl(classAttributeInferenceUncheckedJs1.js, 6, 1)) + } +} + diff --git a/tests/baselines/reference/classAttributeInferenceUncheckedJs1.types b/tests/baselines/reference/classAttributeInferenceUncheckedJs1.types new file mode 100644 index 0000000000000..6a86fd07d0fdc --- /dev/null +++ b/tests/baselines/reference/classAttributeInferenceUncheckedJs1.types @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/classAttributeInferenceUncheckedJs1.ts] //// + +=== classAttributeInferenceUncheckedJs1.js === +class C1 { +>C1 : C1 +> : ^^ + + bar; +>bar : any + + constructor () { + this.foo; +>this.foo : error +>this : this +> : ^^^^ +>foo : any +> : ^^^ + + this.bar; +>this.bar : any +>this : this +> : ^^^^ +>bar : any +> : ^^^ + } +} + +class C2 { +>C2 : C2 +> : ^^ + + #bar; +>#bar : any + + constructor () { + this.#foo; +>this.#foo : error +>this : this +> : ^^^^ + + this.#bar; +>this.#bar : any +>this : this +> : ^^^^ + } +} + diff --git a/tests/baselines/reference/classOptionalFieldReturnTypeInference1.symbols b/tests/baselines/reference/classOptionalFieldReturnTypeInference1.symbols new file mode 100644 index 0000000000000..73b40222e785f --- /dev/null +++ b/tests/baselines/reference/classOptionalFieldReturnTypeInference1.symbols @@ -0,0 +1,165 @@ +//// [tests/cases/compiler/classOptionalFieldReturnTypeInference1.ts] //// + +=== classOptionalFieldReturnTypeInference1.ts === +declare abstract class BasePrompt { +>BasePrompt : Symbol(BasePrompt, Decl(classOptionalFieldReturnTypeInference1.ts, 0, 0)) + + choice( +>choice : Symbol(BasePrompt.choice, Decl(classOptionalFieldReturnTypeInference1.ts, 0, 35)) +>Choice : Symbol(Choice, Decl(classOptionalFieldReturnTypeInference1.ts, 1, 9)) +>Result : Symbol(Result, Decl(classOptionalFieldReturnTypeInference1.ts, 1, 31)) +>Choice : Symbol(Choice, Decl(classOptionalFieldReturnTypeInference1.ts, 1, 9)) + + title: string, +>title : Symbol(title, Decl(classOptionalFieldReturnTypeInference1.ts, 1, 61)) + + choices: readonly Choice[], +>choices : Symbol(choices, Decl(classOptionalFieldReturnTypeInference1.ts, 2, 18)) +>Choice : Symbol(Choice, Decl(classOptionalFieldReturnTypeInference1.ts, 1, 9)) + + ): Promise; +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>Result : Symbol(Result, Decl(classOptionalFieldReturnTypeInference1.ts, 1, 31)) +} + +type MiddlewareNode = { +>MiddlewareNode : Symbol(MiddlewareNode, Decl(classOptionalFieldReturnTypeInference1.ts, 5, 1)) + + name?: string; +>name : Symbol(name, Decl(classOptionalFieldReturnTypeInference1.ts, 7, 23)) + +}; + +declare class Codemods { +>Codemods : Symbol(Codemods, Decl(classOptionalFieldReturnTypeInference1.ts, 9, 2)) + + registerMiddleware( +>registerMiddleware : Symbol(Codemods.registerMiddleware, Decl(classOptionalFieldReturnTypeInference1.ts, 11, 24)) + + stack: "server" | "router" | "named", +>stack : Symbol(stack, Decl(classOptionalFieldReturnTypeInference1.ts, 12, 21)) + + middleware: MiddlewareNode[], +>middleware : Symbol(middleware, Decl(classOptionalFieldReturnTypeInference1.ts, 13, 41)) +>MiddlewareNode : Symbol(MiddlewareNode, Decl(classOptionalFieldReturnTypeInference1.ts, 5, 1)) + + ): Promise; +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +} + +declare class BaseCommand { +>BaseCommand : Symbol(BaseCommand, Decl(classOptionalFieldReturnTypeInference1.ts, 16, 1)) + + prompt: BasePrompt; +>prompt : Symbol(BaseCommand.prompt, Decl(classOptionalFieldReturnTypeInference1.ts, 18, 27)) +>BasePrompt : Symbol(BasePrompt, Decl(classOptionalFieldReturnTypeInference1.ts, 0, 0)) + + createCodemods(): Promise; +>createCodemods : Symbol(BaseCommand.createCodemods, Decl(classOptionalFieldReturnTypeInference1.ts, 19, 21)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>Codemods : Symbol(Codemods, Decl(classOptionalFieldReturnTypeInference1.ts, 9, 2)) +} + +export default class MakeMiddleware extends BaseCommand { +>MakeMiddleware : Symbol(MakeMiddleware, Decl(classOptionalFieldReturnTypeInference1.ts, 21, 1)) +>BaseCommand : Symbol(BaseCommand, Decl(classOptionalFieldReturnTypeInference1.ts, 16, 1)) + + declare name: string; +>name : Symbol(MakeMiddleware.name, Decl(classOptionalFieldReturnTypeInference1.ts, 23, 57)) + + declare stack?: "server" | "named" | "router"; +>stack : Symbol(MakeMiddleware.stack, Decl(classOptionalFieldReturnTypeInference1.ts, 24, 23)) + + + async run() { +>run : Symbol(MakeMiddleware.run, Decl(classOptionalFieldReturnTypeInference1.ts, 26, 48)) + + const stackChoices = ["server", "router", "named"]; +>stackChoices : Symbol(stackChoices, Decl(classOptionalFieldReturnTypeInference1.ts, 30, 9)) + + if (!this.stack) { +>this.stack : Symbol(MakeMiddleware.stack, Decl(classOptionalFieldReturnTypeInference1.ts, 24, 23)) +>this : Symbol(MakeMiddleware, Decl(classOptionalFieldReturnTypeInference1.ts, 21, 1)) +>stack : Symbol(MakeMiddleware.stack, Decl(classOptionalFieldReturnTypeInference1.ts, 24, 23)) + + this.stack = await this.prompt.choice( +>this.stack : Symbol(MakeMiddleware.stack, Decl(classOptionalFieldReturnTypeInference1.ts, 24, 23)) +>this : Symbol(MakeMiddleware, Decl(classOptionalFieldReturnTypeInference1.ts, 21, 1)) +>stack : Symbol(MakeMiddleware.stack, Decl(classOptionalFieldReturnTypeInference1.ts, 24, 23)) +>this.prompt.choice : Symbol(BasePrompt.choice, Decl(classOptionalFieldReturnTypeInference1.ts, 0, 35)) +>this.prompt : Symbol(BaseCommand.prompt, Decl(classOptionalFieldReturnTypeInference1.ts, 18, 27)) +>this : Symbol(MakeMiddleware, Decl(classOptionalFieldReturnTypeInference1.ts, 21, 1)) +>prompt : Symbol(BaseCommand.prompt, Decl(classOptionalFieldReturnTypeInference1.ts, 18, 27)) +>choice : Symbol(BasePrompt.choice, Decl(classOptionalFieldReturnTypeInference1.ts, 0, 35)) + + "Under which stack you want to register the middleware?", + stackChoices, +>stackChoices : Symbol(stackChoices, Decl(classOptionalFieldReturnTypeInference1.ts, 30, 9)) + + ); + } + + if (!stackChoices.includes(this.stack)) { +>stackChoices.includes : Symbol(Array.includes, Decl(lib.es2016.array.include.d.ts, --, --)) +>stackChoices : Symbol(stackChoices, Decl(classOptionalFieldReturnTypeInference1.ts, 30, 9)) +>includes : Symbol(Array.includes, Decl(lib.es2016.array.include.d.ts, --, --)) +>this.stack : Symbol(MakeMiddleware.stack, Decl(classOptionalFieldReturnTypeInference1.ts, 24, 23)) +>this : Symbol(MakeMiddleware, Decl(classOptionalFieldReturnTypeInference1.ts, 21, 1)) +>stack : Symbol(MakeMiddleware.stack, Decl(classOptionalFieldReturnTypeInference1.ts, 24, 23)) + + return; + } + + const codemods = await this.createCodemods(); +>codemods : Symbol(codemods, Decl(classOptionalFieldReturnTypeInference1.ts, 43, 9)) +>this.createCodemods : Symbol(BaseCommand.createCodemods, Decl(classOptionalFieldReturnTypeInference1.ts, 19, 21)) +>this : Symbol(MakeMiddleware, Decl(classOptionalFieldReturnTypeInference1.ts, 21, 1)) +>createCodemods : Symbol(BaseCommand.createCodemods, Decl(classOptionalFieldReturnTypeInference1.ts, 19, 21)) + + await codemods.registerMiddleware(this.stack, [ +>codemods.registerMiddleware : Symbol(Codemods.registerMiddleware, Decl(classOptionalFieldReturnTypeInference1.ts, 11, 24)) +>codemods : Symbol(codemods, Decl(classOptionalFieldReturnTypeInference1.ts, 43, 9)) +>registerMiddleware : Symbol(Codemods.registerMiddleware, Decl(classOptionalFieldReturnTypeInference1.ts, 11, 24)) +>this.stack : Symbol(MakeMiddleware.stack, Decl(classOptionalFieldReturnTypeInference1.ts, 24, 23)) +>this : Symbol(MakeMiddleware, Decl(classOptionalFieldReturnTypeInference1.ts, 21, 1)) +>stack : Symbol(MakeMiddleware.stack, Decl(classOptionalFieldReturnTypeInference1.ts, 24, 23)) + { + name: this.name, +>name : Symbol(name, Decl(classOptionalFieldReturnTypeInference1.ts, 46, 7)) +>this.name : Symbol(MakeMiddleware.name, Decl(classOptionalFieldReturnTypeInference1.ts, 23, 57)) +>this : Symbol(MakeMiddleware, Decl(classOptionalFieldReturnTypeInference1.ts, 21, 1)) +>name : Symbol(MakeMiddleware.name, Decl(classOptionalFieldReturnTypeInference1.ts, 23, 57)) + + }, + ]); + } +} + +declare function dom$(description: string): T; +>dom$ : Symbol(dom$, Decl(classOptionalFieldReturnTypeInference1.ts, 51, 1)) +>T : Symbol(T, Decl(classOptionalFieldReturnTypeInference1.ts, 53, 22)) +>HTMLElement : Symbol(HTMLElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>description : Symbol(description, Decl(classOptionalFieldReturnTypeInference1.ts, 53, 45)) +>T : Symbol(T, Decl(classOptionalFieldReturnTypeInference1.ts, 53, 22)) + +export abstract class PeekViewWidget { +>PeekViewWidget : Symbol(PeekViewWidget, Decl(classOptionalFieldReturnTypeInference1.ts, 53, 69)) + + protected _titleElement?: HTMLDivElement; +>_titleElement : Symbol(PeekViewWidget._titleElement, Decl(classOptionalFieldReturnTypeInference1.ts, 55, 38)) +>HTMLDivElement : Symbol(HTMLDivElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) + + protected _fillHead(container: HTMLElement, noCloseAction?: boolean): void { +>_fillHead : Symbol(PeekViewWidget._fillHead, Decl(classOptionalFieldReturnTypeInference1.ts, 56, 43)) +>container : Symbol(container, Decl(classOptionalFieldReturnTypeInference1.ts, 58, 22)) +>HTMLElement : Symbol(HTMLElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>noCloseAction : Symbol(noCloseAction, Decl(classOptionalFieldReturnTypeInference1.ts, 58, 45)) + + this._titleElement = dom$(".peekview-title"); +>this._titleElement : Symbol(PeekViewWidget._titleElement, Decl(classOptionalFieldReturnTypeInference1.ts, 55, 38)) +>this : Symbol(PeekViewWidget, Decl(classOptionalFieldReturnTypeInference1.ts, 53, 69)) +>_titleElement : Symbol(PeekViewWidget._titleElement, Decl(classOptionalFieldReturnTypeInference1.ts, 55, 38)) +>dom$ : Symbol(dom$, Decl(classOptionalFieldReturnTypeInference1.ts, 51, 1)) + } +} + diff --git a/tests/baselines/reference/classOptionalFieldReturnTypeInference1.types b/tests/baselines/reference/classOptionalFieldReturnTypeInference1.types new file mode 100644 index 0000000000000..574a42b8d2612 --- /dev/null +++ b/tests/baselines/reference/classOptionalFieldReturnTypeInference1.types @@ -0,0 +1,253 @@ +//// [tests/cases/compiler/classOptionalFieldReturnTypeInference1.ts] //// + +=== classOptionalFieldReturnTypeInference1.ts === +declare abstract class BasePrompt { +>BasePrompt : BasePrompt +> : ^^^^^^^^^^ + + choice( +>choice : (title: string, choices: readonly Choice[]) => Promise +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^ + + title: string, +>title : string +> : ^^^^^^ + + choices: readonly Choice[], +>choices : readonly Choice[] +> : ^^^^^^^^^^^^^^^^^ + + ): Promise; +} + +type MiddlewareNode = { +>MiddlewareNode : MiddlewareNode +> : ^^^^^^^^^^^^^^ + + name?: string; +>name : string | undefined +> : ^^^^^^^^^^^^^^^^^^ + +}; + +declare class Codemods { +>Codemods : Codemods +> : ^^^^^^^^ + + registerMiddleware( +>registerMiddleware : (stack: "server" | "router" | "named", middleware: MiddlewareNode[]) => Promise +> : ^ ^^ ^^ ^^ ^^^^^ + + stack: "server" | "router" | "named", +>stack : "server" | "router" | "named" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + middleware: MiddlewareNode[], +>middleware : MiddlewareNode[] +> : ^^^^^^^^^^^^^^^^ + + ): Promise; +} + +declare class BaseCommand { +>BaseCommand : BaseCommand +> : ^^^^^^^^^^^ + + prompt: BasePrompt; +>prompt : BasePrompt +> : ^^^^^^^^^^ + + createCodemods(): Promise; +>createCodemods : () => Promise +> : ^^^^^^ +} + +export default class MakeMiddleware extends BaseCommand { +>MakeMiddleware : MakeMiddleware +> : ^^^^^^^^^^^^^^ +>BaseCommand : BaseCommand +> : ^^^^^^^^^^^ + + declare name: string; +>name : string +> : ^^^^^^ + + declare stack?: "server" | "named" | "router"; +>stack : "server" | "router" | "named" | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + + async run() { +>run : () => Promise +> : ^^^^^^^^^^^^^^^^^^^ + + const stackChoices = ["server", "router", "named"]; +>stackChoices : string[] +> : ^^^^^^^^ +>["server", "router", "named"] : string[] +> : ^^^^^^^^ +>"server" : "server" +> : ^^^^^^^^ +>"router" : "router" +> : ^^^^^^^^ +>"named" : "named" +> : ^^^^^^^ + + if (!this.stack) { +>!this.stack : boolean +> : ^^^^^^^ +>this.stack : "server" | "router" | "named" | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this : this +> : ^^^^ +>stack : "server" | "router" | "named" | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + this.stack = await this.prompt.choice( +>this.stack = await this.prompt.choice( "Under which stack you want to register the middleware?", stackChoices, ) : "server" | "router" | "named" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.stack : "server" | "router" | "named" | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this : this +> : ^^^^ +>stack : "server" | "router" | "named" | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>await this.prompt.choice( "Under which stack you want to register the middleware?", stackChoices, ) : "server" | "router" | "named" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.prompt.choice( "Under which stack you want to register the middleware?", stackChoices, ) : Promise<"server" | "router" | "named"> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.prompt.choice : (title: string, choices: readonly Choice[]) => Promise +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^ +>this.prompt : BasePrompt +> : ^^^^^^^^^^ +>this : this +> : ^^^^ +>prompt : BasePrompt +> : ^^^^^^^^^^ +>choice : (title: string, choices: readonly Choice[]) => Promise +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^ + + "Under which stack you want to register the middleware?", +>"Under which stack you want to register the middleware?" : "Under which stack you want to register the middleware?" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + stackChoices, +>stackChoices : string[] +> : ^^^^^^^^ + + ); + } + + if (!stackChoices.includes(this.stack)) { +>!stackChoices.includes(this.stack) : boolean +> : ^^^^^^^ +>stackChoices.includes(this.stack) : boolean +> : ^^^^^^^ +>stackChoices.includes : (searchElement: string, fromIndex?: number) => boolean +> : ^ ^^^^^^^^^^ ^^^ ^^^^^ +>stackChoices : string[] +> : ^^^^^^^^ +>includes : (searchElement: string, fromIndex?: number) => boolean +> : ^ ^^^^^^^^^^ ^^^ ^^^^^ +>this.stack : "server" | "router" | "named" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this : this +> : ^^^^ +>stack : "server" | "router" | "named" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + return; + } + + const codemods = await this.createCodemods(); +>codemods : Codemods +> : ^^^^^^^^ +>await this.createCodemods() : Codemods +> : ^^^^^^^^ +>this.createCodemods() : Promise +> : ^^^^^^^^^^^^^^^^^ +>this.createCodemods : () => Promise +> : ^^^^^^ +>this : this +> : ^^^^ +>createCodemods : () => Promise +> : ^^^^^^ + + await codemods.registerMiddleware(this.stack, [ +>await codemods.registerMiddleware(this.stack, [ { name: this.name, }, ]) : void +> : ^^^^ +>codemods.registerMiddleware(this.stack, [ { name: this.name, }, ]) : Promise +> : ^^^^^^^^^^^^^ +>codemods.registerMiddleware : (stack: "server" | "router" | "named", middleware: MiddlewareNode[]) => Promise +> : ^ ^^ ^^ ^^ ^^^^^ +>codemods : Codemods +> : ^^^^^^^^ +>registerMiddleware : (stack: "server" | "router" | "named", middleware: MiddlewareNode[]) => Promise +> : ^ ^^ ^^ ^^ ^^^^^ +>this.stack : "server" | "router" | "named" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this : this +> : ^^^^ +>stack : "server" | "router" | "named" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>[ { name: this.name, }, ] : { name: string; }[] +> : ^^^^^^^^^^^^^^^^^^^ + { +>{ name: this.name, } : { name: string; } +> : ^^^^^^^^^^^^^^^^^ + + name: this.name, +>name : string +> : ^^^^^^ +>this.name : string +> : ^^^^^^ +>this : this +> : ^^^^ +>name : string +> : ^^^^^^ + + }, + ]); + } +} + +declare function dom$(description: string): T; +>dom$ : (description: string) => T +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>description : string +> : ^^^^^^ + +export abstract class PeekViewWidget { +>PeekViewWidget : PeekViewWidget +> : ^^^^^^^^^^^^^^ + + protected _titleElement?: HTMLDivElement; +>_titleElement : HTMLDivElement | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ + + protected _fillHead(container: HTMLElement, noCloseAction?: boolean): void { +>_fillHead : (container: HTMLElement, noCloseAction?: boolean) => void +> : ^ ^^ ^^ ^^^ ^^^^^ +>container : HTMLElement +> : ^^^^^^^^^^^ +>noCloseAction : boolean | undefined +> : ^^^^^^^^^^^^^^^^^^^ + + this._titleElement = dom$(".peekview-title"); +>this._titleElement = dom$(".peekview-title") : HTMLDivElement +> : ^^^^^^^^^^^^^^ +>this._titleElement : HTMLDivElement | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this : this +> : ^^^^ +>_titleElement : HTMLDivElement | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>dom$(".peekview-title") : HTMLDivElement +> : ^^^^^^^^^^^^^^ +>dom$ : (description: string) => T +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>".peekview-title" : ".peekview-title" +> : ^^^^^^^^^^^^^^^^^ + } +} + diff --git a/tests/baselines/reference/classPropInitializationInferenceWithElementAccess.symbols b/tests/baselines/reference/classPropInitializationInferenceWithElementAccess.symbols index 04da38aefbd25..4cdde30e60f16 100644 --- a/tests/baselines/reference/classPropInitializationInferenceWithElementAccess.symbols +++ b/tests/baselines/reference/classPropInitializationInferenceWithElementAccess.symbols @@ -41,3 +41,46 @@ export class Cls { >seed : Symbol(seed, Decl(classPropInitializationInferenceWithElementAccess.ts, 8, 16)) } } + +export class Cls2 { +>Cls2 : Symbol(Cls2, Decl(classPropInitializationInferenceWithElementAccess.ts, 15, 1)) + + x; +>x : Symbol(Cls2.x, Decl(classPropInitializationInferenceWithElementAccess.ts, 17, 19)) + + y; +>y : Symbol(Cls2.y, Decl(classPropInitializationInferenceWithElementAccess.ts, 18, 6)) + + z; +>z : Symbol(Cls2.z, Decl(classPropInitializationInferenceWithElementAccess.ts, 19, 6)) + + 0; +>0 : Symbol(Cls2[0], Decl(classPropInitializationInferenceWithElementAccess.ts, 20, 6)) + + constructor(seed: number) { +>seed : Symbol(seed, Decl(classPropInitializationInferenceWithElementAccess.ts, 24, 16)) + + (() => { + this['x'] = [seed]; +>this : Symbol(Cls2, Decl(classPropInitializationInferenceWithElementAccess.ts, 15, 1)) +>'x' : Symbol(Cls2.x, Decl(classPropInitializationInferenceWithElementAccess.ts, 17, 19)) +>seed : Symbol(seed, Decl(classPropInitializationInferenceWithElementAccess.ts, 24, 16)) + + this['y'] = { seed }; +>this : Symbol(Cls2, Decl(classPropInitializationInferenceWithElementAccess.ts, 15, 1)) +>'y' : Symbol(Cls2.y, Decl(classPropInitializationInferenceWithElementAccess.ts, 18, 6)) +>seed : Symbol(seed, Decl(classPropInitializationInferenceWithElementAccess.ts, 27, 25)) + + this['z'] = `${seed}`; +>this : Symbol(Cls2, Decl(classPropInitializationInferenceWithElementAccess.ts, 15, 1)) +>'z' : Symbol(Cls2.z, Decl(classPropInitializationInferenceWithElementAccess.ts, 19, 6)) +>seed : Symbol(seed, Decl(classPropInitializationInferenceWithElementAccess.ts, 24, 16)) + + this[0] = [seed]; +>this : Symbol(Cls2, Decl(classPropInitializationInferenceWithElementAccess.ts, 15, 1)) +>0 : Symbol(Cls2[0], Decl(classPropInitializationInferenceWithElementAccess.ts, 20, 6)) +>seed : Symbol(seed, Decl(classPropInitializationInferenceWithElementAccess.ts, 24, 16)) + + })(); + } +} diff --git a/tests/baselines/reference/classPropInitializationInferenceWithElementAccess.types b/tests/baselines/reference/classPropInitializationInferenceWithElementAccess.types index a0a173712e93d..f5e276130a7f7 100644 --- a/tests/baselines/reference/classPropInitializationInferenceWithElementAccess.types +++ b/tests/baselines/reference/classPropInitializationInferenceWithElementAccess.types @@ -83,3 +83,95 @@ export class Cls { > : ^^^^^^ } } + +export class Cls2 { +>Cls2 : Cls2 +> : ^^^^ + + x; +>x : number[] +> : ^^^^^^^^ + + y; +>y : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ + + z; +>z : string +> : ^^^^^^ + + 0; +>0 : number[] +> : ^^^^^^^^ + + constructor(seed: number) { +>seed : number +> : ^^^^^^ + + (() => { +>(() => { this['x'] = [seed]; this['y'] = { seed }; this['z'] = `${seed}`; this[0] = [seed]; })() : void +> : ^^^^ +>(() => { this['x'] = [seed]; this['y'] = { seed }; this['z'] = `${seed}`; this[0] = [seed]; }) : () => void +> : ^^^^^^^^^^ +>() => { this['x'] = [seed]; this['y'] = { seed }; this['z'] = `${seed}`; this[0] = [seed]; } : () => void +> : ^^^^^^^^^^ + + this['x'] = [seed]; +>this['x'] = [seed] : number[] +> : ^^^^^^^^ +>this['x'] : number[] +> : ^^^^^^^^ +>this : this +> : ^^^^ +>'x' : "x" +> : ^^^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + + this['y'] = { seed }; +>this['y'] = { seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this['y'] : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this : this +> : ^^^^ +>'y' : "y" +> : ^^^ +>{ seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>seed : number +> : ^^^^^^ + + this['z'] = `${seed}`; +>this['z'] = `${seed}` : string +> : ^^^^^^ +>this['z'] : string +> : ^^^^^^ +>this : this +> : ^^^^ +>'z' : "z" +> : ^^^ +>`${seed}` : string +> : ^^^^^^ +>seed : number +> : ^^^^^^ + + this[0] = [seed]; +>this[0] = [seed] : number[] +> : ^^^^^^^^ +>this[0] : number[] +> : ^^^^^^^^ +>this : this +> : ^^^^ +>0 : 0 +> : ^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + + })(); + } +} diff --git a/tests/baselines/reference/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.errors.txt b/tests/baselines/reference/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.errors.txt new file mode 100644 index 0000000000000..0443c1907e4b3 --- /dev/null +++ b/tests/baselines/reference/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.errors.txt @@ -0,0 +1,59 @@ +classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts(13,29): error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts(19,27): error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts(31,29): error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts(37,27): error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? + + +==== classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts (4 errors) ==== + type State = { type: "running"; speed: number } | { type: "stopped" }; + + declare const initialState: State; + + class Actor1 { + static initialState; + + static { + this.initialState = initialState; + + const localSetAsInitiallyRunning = (speed: number) => { + this.initialState = { type: "running", speed }; + this.initialState = { type: "runnnning", speed }; // error + ~~~~ +!!! error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +!!! related TS6500 classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts:1:16: The expected type comes from property 'type' which is declared here on type 'State' + } + } + + static setAsInitiallyRunning(speed: number) { + this.initialState = { type: "running", speed }; + this.initialState = { type: "runnnning", speed }; // error + ~~~~ +!!! error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +!!! related TS6500 classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts:1:16: The expected type comes from property 'type' which is declared here on type 'State' + } + } + + class Actor2 { + static accessor initialState; + + static { + this.initialState = initialState; + + const localSetAsInitiallyRunning = (speed: number) => { + this.initialState = { type: "running", speed }; + this.initialState = { type: "runnnning", speed }; // error + ~~~~ +!!! error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +!!! related TS6500 classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts:1:16: The expected type comes from property 'type' which is declared here on type 'State' + } + } + + static setAsInitiallyRunning(speed: number) { + this.initialState = { type: "running", speed }; + this.initialState = { type: "runnnning", speed }; // error + ~~~~ +!!! error TS2820: Type '"runnnning"' is not assignable to type '"running" | "stopped"'. Did you mean '"running"'? +!!! related TS6500 classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts:1:16: The expected type comes from property 'type' which is declared here on type 'State' + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.symbols b/tests/baselines/reference/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.symbols new file mode 100644 index 0000000000000..eee588fbe4c80 --- /dev/null +++ b/tests/baselines/reference/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.symbols @@ -0,0 +1,119 @@ +//// [tests/cases/conformance/classes/classStaticBlock/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts] //// + +=== classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts === +type State = { type: "running"; speed: number } | { type: "stopped" }; +>State : Symbol(State, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 0, 0)) +>type : Symbol(type, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 0, 14)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 0, 31)) +>type : Symbol(type, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 0, 51)) + +declare const initialState: State; +>initialState : Symbol(initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 2, 13)) +>State : Symbol(State, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 0, 0)) + +class Actor1 { +>Actor1 : Symbol(Actor1, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 2, 34)) + + static initialState; +>initialState : Symbol(Actor1.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 4, 14)) + + static { + this.initialState = initialState; +>this.initialState : Symbol(Actor1.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 4, 14)) +>this : Symbol(Actor1, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 2, 34)) +>initialState : Symbol(Actor1.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 4, 14)) +>initialState : Symbol(initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 2, 13)) + + const localSetAsInitiallyRunning = (speed: number) => { +>localSetAsInitiallyRunning : Symbol(localSetAsInitiallyRunning, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 10, 9)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 10, 40)) + + this.initialState = { type: "running", speed }; +>this.initialState : Symbol(Actor1.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 4, 14)) +>this : Symbol(Actor1, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 2, 34)) +>initialState : Symbol(Actor1.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 4, 14)) +>type : Symbol(type, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 11, 27)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 11, 44)) + + this.initialState = { type: "runnnning", speed }; // error +>this.initialState : Symbol(Actor1.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 4, 14)) +>this : Symbol(Actor1, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 2, 34)) +>initialState : Symbol(Actor1.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 4, 14)) +>type : Symbol(type, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 12, 27)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 12, 46)) + } + } + + static setAsInitiallyRunning(speed: number) { +>setAsInitiallyRunning : Symbol(Actor1.setAsInitiallyRunning, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 14, 3)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 16, 31)) + + this.initialState = { type: "running", speed }; +>this.initialState : Symbol(Actor1.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 4, 14)) +>this : Symbol(Actor1, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 2, 34)) +>initialState : Symbol(Actor1.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 4, 14)) +>type : Symbol(type, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 17, 25)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 17, 42)) + + this.initialState = { type: "runnnning", speed }; // error +>this.initialState : Symbol(Actor1.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 4, 14)) +>this : Symbol(Actor1, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 2, 34)) +>initialState : Symbol(Actor1.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 4, 14)) +>type : Symbol(type, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 18, 25)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 18, 44)) + } +} + +class Actor2 { +>Actor2 : Symbol(Actor2, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 20, 1)) + + static accessor initialState; +>initialState : Symbol(Actor2.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 22, 14)) + + static { + this.initialState = initialState; +>this.initialState : Symbol(Actor2.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 22, 14)) +>this : Symbol(Actor2, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 20, 1)) +>initialState : Symbol(Actor2.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 22, 14)) +>initialState : Symbol(initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 2, 13)) + + const localSetAsInitiallyRunning = (speed: number) => { +>localSetAsInitiallyRunning : Symbol(localSetAsInitiallyRunning, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 28, 9)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 28, 40)) + + this.initialState = { type: "running", speed }; +>this.initialState : Symbol(Actor2.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 22, 14)) +>this : Symbol(Actor2, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 20, 1)) +>initialState : Symbol(Actor2.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 22, 14)) +>type : Symbol(type, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 29, 27)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 29, 44)) + + this.initialState = { type: "runnnning", speed }; // error +>this.initialState : Symbol(Actor2.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 22, 14)) +>this : Symbol(Actor2, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 20, 1)) +>initialState : Symbol(Actor2.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 22, 14)) +>type : Symbol(type, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 30, 27)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 30, 46)) + } + } + + static setAsInitiallyRunning(speed: number) { +>setAsInitiallyRunning : Symbol(Actor2.setAsInitiallyRunning, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 32, 3)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 34, 31)) + + this.initialState = { type: "running", speed }; +>this.initialState : Symbol(Actor2.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 22, 14)) +>this : Symbol(Actor2, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 20, 1)) +>initialState : Symbol(Actor2.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 22, 14)) +>type : Symbol(type, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 35, 25)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 35, 42)) + + this.initialState = { type: "runnnning", speed }; // error +>this.initialState : Symbol(Actor2.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 22, 14)) +>this : Symbol(Actor2, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 20, 1)) +>initialState : Symbol(Actor2.initialState, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 22, 14)) +>type : Symbol(type, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 36, 25)) +>speed : Symbol(speed, Decl(classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts, 36, 44)) + } +} + diff --git a/tests/baselines/reference/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.types b/tests/baselines/reference/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.types new file mode 100644 index 0000000000000..e69fa951fd309 --- /dev/null +++ b/tests/baselines/reference/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.types @@ -0,0 +1,239 @@ +//// [tests/cases/conformance/classes/classStaticBlock/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts] //// + +=== classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts === +type State = { type: "running"; speed: number } | { type: "stopped" }; +>State : State +> : ^^^^^ +>type : "running" +> : ^^^^^^^^^ +>speed : number +> : ^^^^^^ +>type : "stopped" +> : ^^^^^^^^^ + +declare const initialState: State; +>initialState : State +> : ^^^^^ + +class Actor1 { +>Actor1 : Actor1 +> : ^^^^^^ + + static initialState; +>initialState : State +> : ^^^^^ + + static { + this.initialState = initialState; +>this.initialState = initialState : State +> : ^^^^^ +>this.initialState : State +> : ^^^^^ +>this : typeof Actor1 +> : ^^^^^^^^^^^^^ +>initialState : State +> : ^^^^^ +>initialState : State +> : ^^^^^ + + const localSetAsInitiallyRunning = (speed: number) => { +>localSetAsInitiallyRunning : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>(speed: number) => { this.initialState = { type: "running", speed }; this.initialState = { type: "runnnning", speed }; // error } : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.initialState = { type: "running", speed }; +>this.initialState = { type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.initialState : State +> : ^^^^^ +>this : typeof Actor1 +> : ^^^^^^^^^^^^^ +>initialState : State +> : ^^^^^ +>{ type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "running" +> : ^^^^^^^^^ +>"running" : "running" +> : ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.initialState = { type: "runnnning", speed }; // error +>this.initialState = { type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.initialState : State +> : ^^^^^ +>this : typeof Actor1 +> : ^^^^^^^^^^^^^ +>initialState : State +> : ^^^^^ +>{ type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "runnnning" +> : ^^^^^^^^^^^ +>"runnnning" : "runnnning" +> : ^^^^^^^^^^^ +>speed : number +> : ^^^^^^ + } + } + + static setAsInitiallyRunning(speed: number) { +>setAsInitiallyRunning : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.initialState = { type: "running", speed }; +>this.initialState = { type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.initialState : State +> : ^^^^^ +>this : typeof Actor1 +> : ^^^^^^^^^^^^^ +>initialState : State +> : ^^^^^ +>{ type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "running" +> : ^^^^^^^^^ +>"running" : "running" +> : ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.initialState = { type: "runnnning", speed }; // error +>this.initialState = { type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.initialState : State +> : ^^^^^ +>this : typeof Actor1 +> : ^^^^^^^^^^^^^ +>initialState : State +> : ^^^^^ +>{ type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "runnnning" +> : ^^^^^^^^^^^ +>"runnnning" : "runnnning" +> : ^^^^^^^^^^^ +>speed : number +> : ^^^^^^ + } +} + +class Actor2 { +>Actor2 : Actor2 +> : ^^^^^^ + + static accessor initialState; +>initialState : State +> : ^^^^^ + + static { + this.initialState = initialState; +>this.initialState = initialState : State +> : ^^^^^ +>this.initialState : State +> : ^^^^^ +>this : typeof Actor2 +> : ^^^^^^^^^^^^^ +>initialState : State +> : ^^^^^ +>initialState : State +> : ^^^^^ + + const localSetAsInitiallyRunning = (speed: number) => { +>localSetAsInitiallyRunning : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>(speed: number) => { this.initialState = { type: "running", speed }; this.initialState = { type: "runnnning", speed }; // error } : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.initialState = { type: "running", speed }; +>this.initialState = { type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.initialState : State +> : ^^^^^ +>this : typeof Actor2 +> : ^^^^^^^^^^^^^ +>initialState : State +> : ^^^^^ +>{ type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "running" +> : ^^^^^^^^^ +>"running" : "running" +> : ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.initialState = { type: "runnnning", speed }; // error +>this.initialState = { type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.initialState : State +> : ^^^^^ +>this : typeof Actor2 +> : ^^^^^^^^^^^^^ +>initialState : State +> : ^^^^^ +>{ type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "runnnning" +> : ^^^^^^^^^^^ +>"runnnning" : "runnnning" +> : ^^^^^^^^^^^ +>speed : number +> : ^^^^^^ + } + } + + static setAsInitiallyRunning(speed: number) { +>setAsInitiallyRunning : (speed: number) => void +> : ^ ^^ ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.initialState = { type: "running", speed }; +>this.initialState = { type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.initialState : State +> : ^^^^^ +>this : typeof Actor2 +> : ^^^^^^^^^^^^^ +>initialState : State +> : ^^^^^ +>{ type: "running", speed } : { type: "running"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "running" +> : ^^^^^^^^^ +>"running" : "running" +> : ^^^^^^^^^ +>speed : number +> : ^^^^^^ + + this.initialState = { type: "runnnning", speed }; // error +>this.initialState = { type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>this.initialState : State +> : ^^^^^ +>this : typeof Actor2 +> : ^^^^^^^^^^^^^ +>initialState : State +> : ^^^^^ +>{ type: "runnnning", speed } : { type: "runnnning"; speed: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>type : "runnnning" +> : ^^^^^^^^^^^ +>"runnnning" : "runnnning" +> : ^^^^^^^^^^^ +>speed : number +> : ^^^^^^ + } +} + diff --git a/tests/baselines/reference/classStaticPropInferenceTemplate1.js b/tests/baselines/reference/classStaticPropInferenceTemplate1.js new file mode 100644 index 0000000000000..9de655cde9dcd --- /dev/null +++ b/tests/baselines/reference/classStaticPropInferenceTemplate1.js @@ -0,0 +1,110 @@ +//// [tests/cases/conformance/classes/classStaticBlock/classStaticPropInferenceTemplate1.ts] //// + +//// [classStaticPropInferenceTemplate1.ts] +class MyClass { + static property; + static property2; + + static { + const variable = "something"; + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + } +} + +class MyClass2 { + static accessor property; + static accessor property2; + + static { + const variable = "something"; + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + } +} + +class MyClass3 { + static property; + static property2; + + static { + (() => { + const variable = "something"; + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + })(); + } +} + +class MyClass4 { + static accessor property; + static accessor property2; + + static { + (() => { + const variable = "something"; + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + })(); + } +} + + +//// [classStaticPropInferenceTemplate1.js] +"use strict"; +class MyClass { + static property; + static property2; + static { + const variable = "something"; + this.property = `foo`; + this.property2 = `foo-${variable}`; + const localProperty = `foo-${variable}`; + } +} +class MyClass2 { + static accessor property; + static accessor property2; + static { + const variable = "something"; + this.property = `foo`; + this.property2 = `foo-${variable}`; + const localProperty = `foo-${variable}`; + } +} +class MyClass3 { + static property; + static property2; + static { + (() => { + const variable = "something"; + this.property = `foo`; + this.property2 = `foo-${variable}`; + const localProperty = `foo-${variable}`; + })(); + } +} +class MyClass4 { + static accessor property; + static accessor property2; + static { + (() => { + const variable = "something"; + this.property = `foo`; + this.property2 = `foo-${variable}`; + const localProperty = `foo-${variable}`; + })(); + } +} diff --git a/tests/baselines/reference/classStaticPropInferenceTemplate1.symbols b/tests/baselines/reference/classStaticPropInferenceTemplate1.symbols new file mode 100644 index 0000000000000..500a5840b2730 --- /dev/null +++ b/tests/baselines/reference/classStaticPropInferenceTemplate1.symbols @@ -0,0 +1,129 @@ +//// [tests/cases/conformance/classes/classStaticBlock/classStaticPropInferenceTemplate1.ts] //// + +=== classStaticPropInferenceTemplate1.ts === +class MyClass { +>MyClass : Symbol(MyClass, Decl(classStaticPropInferenceTemplate1.ts, 0, 0)) + + static property; +>property : Symbol(MyClass.property, Decl(classStaticPropInferenceTemplate1.ts, 0, 15)) + + static property2; +>property2 : Symbol(MyClass.property2, Decl(classStaticPropInferenceTemplate1.ts, 1, 18)) + + static { + const variable = "something"; +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 5, 9)) + + this.property = `foo`; +>this.property : Symbol(MyClass.property, Decl(classStaticPropInferenceTemplate1.ts, 0, 15)) +>this : Symbol(MyClass, Decl(classStaticPropInferenceTemplate1.ts, 0, 0)) +>property : Symbol(MyClass.property, Decl(classStaticPropInferenceTemplate1.ts, 0, 15)) + + this.property2 = `foo-${variable}`; +>this.property2 : Symbol(MyClass.property2, Decl(classStaticPropInferenceTemplate1.ts, 1, 18)) +>this : Symbol(MyClass, Decl(classStaticPropInferenceTemplate1.ts, 0, 0)) +>property2 : Symbol(MyClass.property2, Decl(classStaticPropInferenceTemplate1.ts, 1, 18)) +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 5, 9)) + + const localProperty = `foo-${variable}`; +>localProperty : Symbol(localProperty, Decl(classStaticPropInferenceTemplate1.ts, 10, 9)) +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 5, 9)) + } +} + +class MyClass2 { +>MyClass2 : Symbol(MyClass2, Decl(classStaticPropInferenceTemplate1.ts, 12, 1)) + + static accessor property; +>property : Symbol(MyClass2.property, Decl(classStaticPropInferenceTemplate1.ts, 14, 16)) + + static accessor property2; +>property2 : Symbol(MyClass2.property2, Decl(classStaticPropInferenceTemplate1.ts, 15, 27)) + + static { + const variable = "something"; +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 19, 9)) + + this.property = `foo`; +>this.property : Symbol(MyClass2.property, Decl(classStaticPropInferenceTemplate1.ts, 14, 16)) +>this : Symbol(MyClass2, Decl(classStaticPropInferenceTemplate1.ts, 12, 1)) +>property : Symbol(MyClass2.property, Decl(classStaticPropInferenceTemplate1.ts, 14, 16)) + + this.property2 = `foo-${variable}`; +>this.property2 : Symbol(MyClass2.property2, Decl(classStaticPropInferenceTemplate1.ts, 15, 27)) +>this : Symbol(MyClass2, Decl(classStaticPropInferenceTemplate1.ts, 12, 1)) +>property2 : Symbol(MyClass2.property2, Decl(classStaticPropInferenceTemplate1.ts, 15, 27)) +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 19, 9)) + + const localProperty = `foo-${variable}`; +>localProperty : Symbol(localProperty, Decl(classStaticPropInferenceTemplate1.ts, 24, 9)) +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 19, 9)) + } +} + +class MyClass3 { +>MyClass3 : Symbol(MyClass3, Decl(classStaticPropInferenceTemplate1.ts, 26, 1)) + + static property; +>property : Symbol(MyClass3.property, Decl(classStaticPropInferenceTemplate1.ts, 28, 16)) + + static property2; +>property2 : Symbol(MyClass3.property2, Decl(classStaticPropInferenceTemplate1.ts, 29, 18)) + + static { + (() => { + const variable = "something"; +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 34, 11)) + + this.property = `foo`; +>this.property : Symbol(MyClass3.property, Decl(classStaticPropInferenceTemplate1.ts, 28, 16)) +>this : Symbol(MyClass3, Decl(classStaticPropInferenceTemplate1.ts, 26, 1)) +>property : Symbol(MyClass3.property, Decl(classStaticPropInferenceTemplate1.ts, 28, 16)) + + this.property2 = `foo-${variable}`; +>this.property2 : Symbol(MyClass3.property2, Decl(classStaticPropInferenceTemplate1.ts, 29, 18)) +>this : Symbol(MyClass3, Decl(classStaticPropInferenceTemplate1.ts, 26, 1)) +>property2 : Symbol(MyClass3.property2, Decl(classStaticPropInferenceTemplate1.ts, 29, 18)) +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 34, 11)) + + const localProperty = `foo-${variable}`; +>localProperty : Symbol(localProperty, Decl(classStaticPropInferenceTemplate1.ts, 39, 11)) +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 34, 11)) + + })(); + } +} + +class MyClass4 { +>MyClass4 : Symbol(MyClass4, Decl(classStaticPropInferenceTemplate1.ts, 42, 1)) + + static accessor property; +>property : Symbol(MyClass4.property, Decl(classStaticPropInferenceTemplate1.ts, 44, 16)) + + static accessor property2; +>property2 : Symbol(MyClass4.property2, Decl(classStaticPropInferenceTemplate1.ts, 45, 27)) + + static { + (() => { + const variable = "something"; +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 50, 11)) + + this.property = `foo`; +>this.property : Symbol(MyClass4.property, Decl(classStaticPropInferenceTemplate1.ts, 44, 16)) +>this : Symbol(MyClass4, Decl(classStaticPropInferenceTemplate1.ts, 42, 1)) +>property : Symbol(MyClass4.property, Decl(classStaticPropInferenceTemplate1.ts, 44, 16)) + + this.property2 = `foo-${variable}`; +>this.property2 : Symbol(MyClass4.property2, Decl(classStaticPropInferenceTemplate1.ts, 45, 27)) +>this : Symbol(MyClass4, Decl(classStaticPropInferenceTemplate1.ts, 42, 1)) +>property2 : Symbol(MyClass4.property2, Decl(classStaticPropInferenceTemplate1.ts, 45, 27)) +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 50, 11)) + + const localProperty = `foo-${variable}`; +>localProperty : Symbol(localProperty, Decl(classStaticPropInferenceTemplate1.ts, 55, 11)) +>variable : Symbol(variable, Decl(classStaticPropInferenceTemplate1.ts, 50, 11)) + + })(); + } +} + diff --git a/tests/baselines/reference/classStaticPropInferenceTemplate1.types b/tests/baselines/reference/classStaticPropInferenceTemplate1.types new file mode 100644 index 0000000000000..ea5769c1f8186 --- /dev/null +++ b/tests/baselines/reference/classStaticPropInferenceTemplate1.types @@ -0,0 +1,243 @@ +//// [tests/cases/conformance/classes/classStaticBlock/classStaticPropInferenceTemplate1.ts] //// + +=== classStaticPropInferenceTemplate1.ts === +class MyClass { +>MyClass : MyClass +> : ^^^^^^^ + + static property; +>property : string +> : ^^^^^^ + + static property2; +>property2 : string +> : ^^^^^^ + + static { + const variable = "something"; +>variable : "something" +> : ^^^^^^^^^^^ +>"something" : "something" +> : ^^^^^^^^^^^ + + this.property = `foo`; +>this.property = `foo` : "foo" +> : ^^^^^ +>this.property : string +> : ^^^^^^ +>this : typeof MyClass +> : ^^^^^^^^^^^^^^ +>property : string +> : ^^^^^^ +>`foo` : "foo" +> : ^^^^^ + + this.property2 = `foo-${variable}`; +>this.property2 = `foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>this.property2 : string +> : ^^^^^^ +>this : typeof MyClass +> : ^^^^^^^^^^^^^^ +>property2 : string +> : ^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + const localProperty = `foo-${variable}`; +>localProperty : "foo-something" +> : ^^^^^^^^^^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + } +} + +class MyClass2 { +>MyClass2 : MyClass2 +> : ^^^^^^^^ + + static accessor property; +>property : string +> : ^^^^^^ + + static accessor property2; +>property2 : string +> : ^^^^^^ + + static { + const variable = "something"; +>variable : "something" +> : ^^^^^^^^^^^ +>"something" : "something" +> : ^^^^^^^^^^^ + + this.property = `foo`; +>this.property = `foo` : "foo" +> : ^^^^^ +>this.property : string +> : ^^^^^^ +>this : typeof MyClass2 +> : ^^^^^^^^^^^^^^^ +>property : string +> : ^^^^^^ +>`foo` : "foo" +> : ^^^^^ + + this.property2 = `foo-${variable}`; +>this.property2 = `foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>this.property2 : string +> : ^^^^^^ +>this : typeof MyClass2 +> : ^^^^^^^^^^^^^^^ +>property2 : string +> : ^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + const localProperty = `foo-${variable}`; +>localProperty : "foo-something" +> : ^^^^^^^^^^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + } +} + +class MyClass3 { +>MyClass3 : MyClass3 +> : ^^^^^^^^ + + static property; +>property : string +> : ^^^^^^ + + static property2; +>property2 : string +> : ^^^^^^ + + static { + (() => { +>(() => { const variable = "something"; this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; })() : void +> : ^^^^ +>(() => { const variable = "something"; this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; }) : () => void +> : ^^^^^^^^^^ +>() => { const variable = "something"; this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; } : () => void +> : ^^^^^^^^^^ + + const variable = "something"; +>variable : "something" +> : ^^^^^^^^^^^ +>"something" : "something" +> : ^^^^^^^^^^^ + + this.property = `foo`; +>this.property = `foo` : "foo" +> : ^^^^^ +>this.property : string +> : ^^^^^^ +>this : typeof MyClass3 +> : ^^^^^^^^^^^^^^^ +>property : string +> : ^^^^^^ +>`foo` : "foo" +> : ^^^^^ + + this.property2 = `foo-${variable}`; +>this.property2 = `foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>this.property2 : string +> : ^^^^^^ +>this : typeof MyClass3 +> : ^^^^^^^^^^^^^^^ +>property2 : string +> : ^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + const localProperty = `foo-${variable}`; +>localProperty : "foo-something" +> : ^^^^^^^^^^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + })(); + } +} + +class MyClass4 { +>MyClass4 : MyClass4 +> : ^^^^^^^^ + + static accessor property; +>property : string +> : ^^^^^^ + + static accessor property2; +>property2 : string +> : ^^^^^^ + + static { + (() => { +>(() => { const variable = "something"; this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; })() : void +> : ^^^^ +>(() => { const variable = "something"; this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; }) : () => void +> : ^^^^^^^^^^ +>() => { const variable = "something"; this.property = `foo`; this.property2 = `foo-${variable}`; const localProperty = `foo-${variable}`; } : () => void +> : ^^^^^^^^^^ + + const variable = "something"; +>variable : "something" +> : ^^^^^^^^^^^ +>"something" : "something" +> : ^^^^^^^^^^^ + + this.property = `foo`; +>this.property = `foo` : "foo" +> : ^^^^^ +>this.property : string +> : ^^^^^^ +>this : typeof MyClass4 +> : ^^^^^^^^^^^^^^^ +>property : string +> : ^^^^^^ +>`foo` : "foo" +> : ^^^^^ + + this.property2 = `foo-${variable}`; +>this.property2 = `foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>this.property2 : string +> : ^^^^^^ +>this : typeof MyClass4 +> : ^^^^^^^^^^^^^^^ +>property2 : string +> : ^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + const localProperty = `foo-${variable}`; +>localProperty : "foo-something" +> : ^^^^^^^^^^^^^^^ +>`foo-${variable}` : "foo-something" +> : ^^^^^^^^^^^^^^^ +>variable : "something" +> : ^^^^^^^^^^^ + + })(); + } +} + diff --git a/tests/baselines/reference/classStaticPropInitializationInferenceWithElementAccess1.js b/tests/baselines/reference/classStaticPropInitializationInferenceWithElementAccess1.js new file mode 100644 index 0000000000000..a16e3c967b570 --- /dev/null +++ b/tests/baselines/reference/classStaticPropInitializationInferenceWithElementAccess1.js @@ -0,0 +1,163 @@ +//// [tests/cases/conformance/classes/classStaticBlock/classStaticPropInitializationInferenceWithElementAccess1.ts] //// + +//// [classStaticPropInitializationInferenceWithElementAccess1.ts] +let seed = 0; + +export class Cls1 { + static x; + static y; + static z; + + static 0; + + static { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + + this[0] = [seed]; + } +} + +export class Cls2 { + static accessor x; + static accessor y; + static accessor z; + + static accessor 0; + + static { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + + this[0] = [seed]; + } +} + +export class Cls3 { + static x; + static y; + static z; + + static 0; + + static { + (() => { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + + this[0] = [seed]; + })(); + } +} + +export class Cls4 { + static accessor x; + static accessor y; + static accessor z; + + static accessor 0; + + static { + (() => { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + + this[0] = [seed]; + })(); + } +} + + +//// [classStaticPropInitializationInferenceWithElementAccess1.js] +let seed = 0; +export class Cls1 { + static x; + static y; + static z; + static 0; + static { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + this[0] = [seed]; + } +} +export class Cls2 { + static accessor x; + static accessor y; + static accessor z; + static accessor 0; + static { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + this[0] = [seed]; + } +} +export class Cls3 { + static x; + static y; + static z; + static 0; + static { + (() => { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + this[0] = [seed]; + })(); + } +} +export class Cls4 { + static accessor x; + static accessor y; + static accessor z; + static accessor 0; + static { + (() => { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + this[0] = [seed]; + })(); + } +} + + +//// [classStaticPropInitializationInferenceWithElementAccess1.d.ts] +export declare class Cls1 { + static x: number[]; + static y: { + seed: number; + }; + static z: string; + static 0: number[]; +} +export declare class Cls2 { + static accessor x: number[]; + static accessor y: { + seed: number; + }; + static accessor z: string; + static accessor 0: number[]; +} +export declare class Cls3 { + static x: number[]; + static y: { + seed: number; + }; + static z: string; + static 0: number[]; +} +export declare class Cls4 { + static accessor x: number[]; + static accessor y: { + seed: number; + }; + static accessor z: string; + static accessor 0: number[]; +} diff --git a/tests/baselines/reference/classStaticPropInitializationInferenceWithElementAccess1.symbols b/tests/baselines/reference/classStaticPropInitializationInferenceWithElementAccess1.symbols new file mode 100644 index 0000000000000..f311a7957dede --- /dev/null +++ b/tests/baselines/reference/classStaticPropInitializationInferenceWithElementAccess1.symbols @@ -0,0 +1,164 @@ +//// [tests/cases/conformance/classes/classStaticBlock/classStaticPropInitializationInferenceWithElementAccess1.ts] //// + +=== classStaticPropInitializationInferenceWithElementAccess1.ts === +let seed = 0; +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + +export class Cls1 { +>Cls1 : Symbol(Cls1, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 13)) + + static x; +>x : Symbol(Cls1.x, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 2, 19)) + + static y; +>y : Symbol(Cls1.y, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 3, 11)) + + static z; +>z : Symbol(Cls1.z, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 4, 11)) + + static 0; +>0 : Symbol(Cls1[0], Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 5, 11)) + + static { + this["x"] = [seed]; +>this : Symbol(Cls1, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 13)) +>"x" : Symbol(Cls1.x, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 2, 19)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + + this["y"] = { seed }; +>this : Symbol(Cls1, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 13)) +>"y" : Symbol(Cls1.y, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 3, 11)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 11, 17)) + + this["z"] = `${seed}`; +>this : Symbol(Cls1, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 13)) +>"z" : Symbol(Cls1.z, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 4, 11)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + + this[0] = [seed]; +>this : Symbol(Cls1, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 13)) +>0 : Symbol(Cls1[0], Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 5, 11)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + } +} + +export class Cls2 { +>Cls2 : Symbol(Cls2, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 16, 1)) + + static accessor x; +>x : Symbol(Cls2.x, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 18, 19)) + + static accessor y; +>y : Symbol(Cls2.y, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 19, 20)) + + static accessor z; +>z : Symbol(Cls2.z, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 20, 20)) + + static accessor 0; +>0 : Symbol(Cls2[0], Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 21, 20)) + + static { + this["x"] = [seed]; +>this : Symbol(Cls2, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 16, 1)) +>"x" : Symbol(Cls2.x, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 18, 19)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + + this["y"] = { seed }; +>this : Symbol(Cls2, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 16, 1)) +>"y" : Symbol(Cls2.y, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 19, 20)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 27, 17)) + + this["z"] = `${seed}`; +>this : Symbol(Cls2, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 16, 1)) +>"z" : Symbol(Cls2.z, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 20, 20)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + + this[0] = [seed]; +>this : Symbol(Cls2, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 16, 1)) +>0 : Symbol(Cls2[0], Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 21, 20)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + } +} + +export class Cls3 { +>Cls3 : Symbol(Cls3, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 32, 1)) + + static x; +>x : Symbol(Cls3.x, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 34, 19)) + + static y; +>y : Symbol(Cls3.y, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 35, 11)) + + static z; +>z : Symbol(Cls3.z, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 36, 11)) + + static 0; +>0 : Symbol(Cls3[0], Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 37, 11)) + + static { + (() => { + this["x"] = [seed]; +>this : Symbol(Cls3, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 32, 1)) +>"x" : Symbol(Cls3.x, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 34, 19)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + + this["y"] = { seed }; +>this : Symbol(Cls3, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 32, 1)) +>"y" : Symbol(Cls3.y, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 35, 11)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 44, 19)) + + this["z"] = `${seed}`; +>this : Symbol(Cls3, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 32, 1)) +>"z" : Symbol(Cls3.z, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 36, 11)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + + this[0] = [seed]; +>this : Symbol(Cls3, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 32, 1)) +>0 : Symbol(Cls3[0], Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 37, 11)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + + })(); + } +} + +export class Cls4 { +>Cls4 : Symbol(Cls4, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 50, 1)) + + static accessor x; +>x : Symbol(Cls4.x, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 52, 19)) + + static accessor y; +>y : Symbol(Cls4.y, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 53, 20)) + + static accessor z; +>z : Symbol(Cls4.z, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 54, 20)) + + static accessor 0; +>0 : Symbol(Cls4[0], Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 55, 20)) + + static { + (() => { + this["x"] = [seed]; +>this : Symbol(Cls4, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 50, 1)) +>"x" : Symbol(Cls4.x, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 52, 19)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + + this["y"] = { seed }; +>this : Symbol(Cls4, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 50, 1)) +>"y" : Symbol(Cls4.y, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 53, 20)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 62, 19)) + + this["z"] = `${seed}`; +>this : Symbol(Cls4, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 50, 1)) +>"z" : Symbol(Cls4.z, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 54, 20)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + + this[0] = [seed]; +>this : Symbol(Cls4, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 50, 1)) +>0 : Symbol(Cls4[0], Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 55, 20)) +>seed : Symbol(seed, Decl(classStaticPropInitializationInferenceWithElementAccess1.ts, 0, 3)) + + })(); + } +} + diff --git a/tests/baselines/reference/classStaticPropInitializationInferenceWithElementAccess1.types b/tests/baselines/reference/classStaticPropInitializationInferenceWithElementAccess1.types new file mode 100644 index 0000000000000..a09856b676bd6 --- /dev/null +++ b/tests/baselines/reference/classStaticPropInitializationInferenceWithElementAccess1.types @@ -0,0 +1,345 @@ +//// [tests/cases/conformance/classes/classStaticBlock/classStaticPropInitializationInferenceWithElementAccess1.ts] //// + +=== classStaticPropInitializationInferenceWithElementAccess1.ts === +let seed = 0; +>seed : number +> : ^^^^^^ +>0 : 0 +> : ^ + +export class Cls1 { +>Cls1 : Cls1 +> : ^^^^ + + static x; +>x : number[] +> : ^^^^^^^^ + + static y; +>y : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ + + static z; +>z : string +> : ^^^^^^ + + static 0; +>0 : number[] +> : ^^^^^^^^ + + static { + this["x"] = [seed]; +>this["x"] = [seed] : number[] +> : ^^^^^^^^ +>this["x"] : number[] +> : ^^^^^^^^ +>this : typeof Cls1 +> : ^^^^^^^^^^^ +>"x" : "x" +> : ^^^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + + this["y"] = { seed }; +>this["y"] = { seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this["y"] : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this : typeof Cls1 +> : ^^^^^^^^^^^ +>"y" : "y" +> : ^^^ +>{ seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>seed : number +> : ^^^^^^ + + this["z"] = `${seed}`; +>this["z"] = `${seed}` : string +> : ^^^^^^ +>this["z"] : string +> : ^^^^^^ +>this : typeof Cls1 +> : ^^^^^^^^^^^ +>"z" : "z" +> : ^^^ +>`${seed}` : string +> : ^^^^^^ +>seed : number +> : ^^^^^^ + + this[0] = [seed]; +>this[0] = [seed] : number[] +> : ^^^^^^^^ +>this[0] : number[] +> : ^^^^^^^^ +>this : typeof Cls1 +> : ^^^^^^^^^^^ +>0 : 0 +> : ^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + } +} + +export class Cls2 { +>Cls2 : Cls2 +> : ^^^^ + + static accessor x; +>x : number[] +> : ^^^^^^^^ + + static accessor y; +>y : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ + + static accessor z; +>z : string +> : ^^^^^^ + + static accessor 0; +>0 : number[] +> : ^^^^^^^^ + + static { + this["x"] = [seed]; +>this["x"] = [seed] : number[] +> : ^^^^^^^^ +>this["x"] : number[] +> : ^^^^^^^^ +>this : typeof Cls2 +> : ^^^^^^^^^^^ +>"x" : "x" +> : ^^^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + + this["y"] = { seed }; +>this["y"] = { seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this["y"] : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this : typeof Cls2 +> : ^^^^^^^^^^^ +>"y" : "y" +> : ^^^ +>{ seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>seed : number +> : ^^^^^^ + + this["z"] = `${seed}`; +>this["z"] = `${seed}` : string +> : ^^^^^^ +>this["z"] : string +> : ^^^^^^ +>this : typeof Cls2 +> : ^^^^^^^^^^^ +>"z" : "z" +> : ^^^ +>`${seed}` : string +> : ^^^^^^ +>seed : number +> : ^^^^^^ + + this[0] = [seed]; +>this[0] = [seed] : number[] +> : ^^^^^^^^ +>this[0] : number[] +> : ^^^^^^^^ +>this : typeof Cls2 +> : ^^^^^^^^^^^ +>0 : 0 +> : ^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + } +} + +export class Cls3 { +>Cls3 : Cls3 +> : ^^^^ + + static x; +>x : number[] +> : ^^^^^^^^ + + static y; +>y : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ + + static z; +>z : string +> : ^^^^^^ + + static 0; +>0 : number[] +> : ^^^^^^^^ + + static { + (() => { +>(() => { this["x"] = [seed]; this["y"] = { seed }; this["z"] = `${seed}`; this[0] = [seed]; })() : void +> : ^^^^ +>(() => { this["x"] = [seed]; this["y"] = { seed }; this["z"] = `${seed}`; this[0] = [seed]; }) : () => void +> : ^^^^^^^^^^ +>() => { this["x"] = [seed]; this["y"] = { seed }; this["z"] = `${seed}`; this[0] = [seed]; } : () => void +> : ^^^^^^^^^^ + + this["x"] = [seed]; +>this["x"] = [seed] : number[] +> : ^^^^^^^^ +>this["x"] : number[] +> : ^^^^^^^^ +>this : typeof Cls3 +> : ^^^^^^^^^^^ +>"x" : "x" +> : ^^^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + + this["y"] = { seed }; +>this["y"] = { seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this["y"] : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this : typeof Cls3 +> : ^^^^^^^^^^^ +>"y" : "y" +> : ^^^ +>{ seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>seed : number +> : ^^^^^^ + + this["z"] = `${seed}`; +>this["z"] = `${seed}` : string +> : ^^^^^^ +>this["z"] : string +> : ^^^^^^ +>this : typeof Cls3 +> : ^^^^^^^^^^^ +>"z" : "z" +> : ^^^ +>`${seed}` : string +> : ^^^^^^ +>seed : number +> : ^^^^^^ + + this[0] = [seed]; +>this[0] = [seed] : number[] +> : ^^^^^^^^ +>this[0] : number[] +> : ^^^^^^^^ +>this : typeof Cls3 +> : ^^^^^^^^^^^ +>0 : 0 +> : ^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + + })(); + } +} + +export class Cls4 { +>Cls4 : Cls4 +> : ^^^^ + + static accessor x; +>x : number[] +> : ^^^^^^^^ + + static accessor y; +>y : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ + + static accessor z; +>z : string +> : ^^^^^^ + + static accessor 0; +>0 : number[] +> : ^^^^^^^^ + + static { + (() => { +>(() => { this["x"] = [seed]; this["y"] = { seed }; this["z"] = `${seed}`; this[0] = [seed]; })() : void +> : ^^^^ +>(() => { this["x"] = [seed]; this["y"] = { seed }; this["z"] = `${seed}`; this[0] = [seed]; }) : () => void +> : ^^^^^^^^^^ +>() => { this["x"] = [seed]; this["y"] = { seed }; this["z"] = `${seed}`; this[0] = [seed]; } : () => void +> : ^^^^^^^^^^ + + this["x"] = [seed]; +>this["x"] = [seed] : number[] +> : ^^^^^^^^ +>this["x"] : number[] +> : ^^^^^^^^ +>this : typeof Cls4 +> : ^^^^^^^^^^^ +>"x" : "x" +> : ^^^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + + this["y"] = { seed }; +>this["y"] = { seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this["y"] : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>this : typeof Cls4 +> : ^^^^^^^^^^^ +>"y" : "y" +> : ^^^ +>{ seed } : { seed: number; } +> : ^^^^^^^^^^^^^^^^^ +>seed : number +> : ^^^^^^ + + this["z"] = `${seed}`; +>this["z"] = `${seed}` : string +> : ^^^^^^ +>this["z"] : string +> : ^^^^^^ +>this : typeof Cls4 +> : ^^^^^^^^^^^ +>"z" : "z" +> : ^^^ +>`${seed}` : string +> : ^^^^^^ +>seed : number +> : ^^^^^^ + + this[0] = [seed]; +>this[0] = [seed] : number[] +> : ^^^^^^^^ +>this[0] : number[] +> : ^^^^^^^^ +>this : typeof Cls4 +> : ^^^^^^^^^^^ +>0 : 0 +> : ^ +>[seed] : number[] +> : ^^^^^^^^ +>seed : number +> : ^^^^^^ + + })(); + } +} + diff --git a/tests/cases/compiler/classAccessorInitializationInferenceWithElementAccess1.ts b/tests/cases/compiler/classAccessorInitializationInferenceWithElementAccess1.ts index 8f8b891532d7d..59ba81b2890b9 100644 --- a/tests/cases/compiler/classAccessorInitializationInferenceWithElementAccess1.ts +++ b/tests/cases/compiler/classAccessorInitializationInferenceWithElementAccess1.ts @@ -17,3 +17,21 @@ export class Cls { this[0] = [seed]; } } + +export class Cls2 { + accessor x; + accessor y; + accessor z; + + accessor 0; + + constructor(seed: number) { + (() => { + this['x'] = [seed]; + this['y'] = { seed }; + this['z'] = `${seed}`; + + this[0] = [seed]; + })(); + } +} diff --git a/tests/cases/compiler/classAttributeInferenceContextualTypingOutsideOfConstructor1.ts b/tests/cases/compiler/classAttributeInferenceContextualTypingOutsideOfConstructor1.ts new file mode 100644 index 0000000000000..7843d8c9b6687 --- /dev/null +++ b/tests/cases/compiler/classAttributeInferenceContextualTypingOutsideOfConstructor1.ts @@ -0,0 +1,45 @@ +// @strict: true +// @noEmit: true +// @target: esnext + +// https://github.com/microsoft/TypeScript/issues/60394 + +type State = { type: "running"; speed: number } | { type: "stopped" }; + +declare const initialState: State; + +class Actor1 { + private state; + + constructor() { + this.state = initialState; + + const localRun = (speed: number) => { + this.state = { type: "running", speed }; + this.state = { type: "runnnning", speed }; // error + } + } + + run(speed: number) { + this.state = { type: "running", speed }; + this.state = { type: "runnnning", speed }; // error + } +} + +class Actor2 { + accessor state; + + constructor() { + this.state = initialState; + + const localRun = (speed: number) => { + this.state = { type: "running", speed }; + this.state = { type: "runnnning", speed }; // error + } + } + + run(speed: number) { + this.state = { type: "running", speed }; + this.state = { type: "runnnning", speed }; // error + } +} diff --git a/tests/cases/compiler/classAttributeInferenceTemplate.ts b/tests/cases/compiler/classAttributeInferenceTemplate.ts index c876482a39c8a..20bb47c94d1b6 100644 --- a/tests/cases/compiler/classAttributeInferenceTemplate.ts +++ b/tests/cases/compiler/classAttributeInferenceTemplate.ts @@ -7,10 +7,10 @@ class MyClass { constructor() { const variable = 'something' - this.property = `foo`; // Correctly inferred as `string` - this.property2 = `foo-${variable}`; // Causes an error + this.property = `foo`; + this.property2 = `foo-${variable}`; - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; } } @@ -21,9 +21,41 @@ class MyClass2 { constructor() { const variable = 'something' - this.property = `foo`; // Correctly inferred as `string` - this.property2 = `foo-${variable}`; // Causes an error + this.property = `foo`; + this.property2 = `foo-${variable}`; - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; + } +} + +class MyClass3 { + property; + property2; + + constructor() { + (() => { + const variable = 'something' + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + })(); + } +} + +class MyClass4 { + accessor property; + accessor property2; + + constructor() { + (() => { + const variable = 'something' + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + })(); } } diff --git a/tests/cases/compiler/classAttributeInferenceTemplateJS.ts b/tests/cases/compiler/classAttributeInferenceTemplateJS.ts index a35fd951d5480..f1772e96cb4a9 100644 --- a/tests/cases/compiler/classAttributeInferenceTemplateJS.ts +++ b/tests/cases/compiler/classAttributeInferenceTemplateJS.ts @@ -10,10 +10,10 @@ class MyClass { constructor() { const variable = 'something' - this.property = `foo`; // Correctly inferred as `string` - this.property2 = `foo-${variable}`; // Causes an error + this.property = `foo`; + this.property2 = `foo-${variable}`; - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; } } @@ -24,9 +24,41 @@ class MyClass2 { constructor() { const variable = 'something' - this.property = `foo`; // Correctly inferred as `string` - this.property2 = `foo-${variable}`; // Causes an error + this.property = `foo`; + this.property2 = `foo-${variable}`; - const localProperty = `foo-${variable}`; // Correctly inferred as `string` + const localProperty = `foo-${variable}`; + } +} + +class MyClass3 { + property; + property2; + + constructor() { + (() => { + const variable = 'something' + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + })(); + } +} + +class MyClass4 { + accessor property; + accessor property2; + + constructor() { + (() => { + const variable = 'something' + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + })(); } } diff --git a/tests/cases/compiler/classAttributeInferenceUncheckedJs1.ts b/tests/cases/compiler/classAttributeInferenceUncheckedJs1.ts new file mode 100644 index 0000000000000..95e57d75e8e29 --- /dev/null +++ b/tests/cases/compiler/classAttributeInferenceUncheckedJs1.ts @@ -0,0 +1,21 @@ +// @allowJs: true +// @checkJs: false +// @noEmit: true +// @Filename: classAttributeInferenceUncheckedJs1.js +// @target: es2015 + +class C1 { + bar; + constructor () { + this.foo; + this.bar; + } +} + +class C2 { + #bar; + constructor () { + this.#foo; + this.#bar; + } +} diff --git a/tests/cases/compiler/classOptionalFieldReturnTypeInference1.ts b/tests/cases/compiler/classOptionalFieldReturnTypeInference1.ts new file mode 100644 index 0000000000000..bd72fefed7580 --- /dev/null +++ b/tests/cases/compiler/classOptionalFieldReturnTypeInference1.ts @@ -0,0 +1,67 @@ +// @strict: true +// @target: esnext +// @lib: esnext,dom +// @noEmit: true + +declare abstract class BasePrompt { + choice( + title: string, + choices: readonly Choice[], + ): Promise; +} + +type MiddlewareNode = { + name?: string; +}; + +declare class Codemods { + registerMiddleware( + stack: "server" | "router" | "named", + middleware: MiddlewareNode[], + ): Promise; +} + +declare class BaseCommand { + prompt: BasePrompt; + createCodemods(): Promise; +} + +export default class MakeMiddleware extends BaseCommand { + declare name: string; + + declare stack?: "server" | "named" | "router"; + + + async run() { + const stackChoices = ["server", "router", "named"]; + + if (!this.stack) { + this.stack = await this.prompt.choice( + "Under which stack you want to register the middleware?", + stackChoices, + ); + } + + if (!stackChoices.includes(this.stack)) { + return; + } + + const codemods = await this.createCodemods(); + + await codemods.registerMiddleware(this.stack, [ + { + name: this.name, + }, + ]); + } +} + +declare function dom$(description: string): T; + +export abstract class PeekViewWidget { + protected _titleElement?: HTMLDivElement; + + protected _fillHead(container: HTMLElement, noCloseAction?: boolean): void { + this._titleElement = dom$(".peekview-title"); + } +} diff --git a/tests/cases/compiler/classPropInitializationInferenceWithElementAccess.ts b/tests/cases/compiler/classPropInitializationInferenceWithElementAccess.ts index 7bd1920a7d6dc..e0d0efe2a6d5c 100644 --- a/tests/cases/compiler/classPropInitializationInferenceWithElementAccess.ts +++ b/tests/cases/compiler/classPropInitializationInferenceWithElementAccess.ts @@ -16,4 +16,22 @@ export class Cls { this[0] = [seed]; } +} + +export class Cls2 { + x; + y; + z; + + 0; + + constructor(seed: number) { + (() => { + this['x'] = [seed]; + this['y'] = { seed }; + this['z'] = `${seed}`; + + this[0] = [seed]; + })(); + } } \ No newline at end of file diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts new file mode 100644 index 0000000000000..df4e9dbd594f3 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticFieldInferenceContextualTypingOutsideOfStaticBlock1.ts @@ -0,0 +1,43 @@ +// @strict: true +// @noEmit: true +// @target: esnext + +type State = { type: "running"; speed: number } | { type: "stopped" }; + +declare const initialState: State; + +class Actor1 { + static initialState; + + static { + this.initialState = initialState; + + const localSetAsInitiallyRunning = (speed: number) => { + this.initialState = { type: "running", speed }; + this.initialState = { type: "runnnning", speed }; // error + } + } + + static setAsInitiallyRunning(speed: number) { + this.initialState = { type: "running", speed }; + this.initialState = { type: "runnnning", speed }; // error + } +} + +class Actor2 { + static accessor initialState; + + static { + this.initialState = initialState; + + const localSetAsInitiallyRunning = (speed: number) => { + this.initialState = { type: "running", speed }; + this.initialState = { type: "runnnning", speed }; // error + } + } + + static setAsInitiallyRunning(speed: number) { + this.initialState = { type: "running", speed }; + this.initialState = { type: "runnnning", speed }; // error + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticPropInferenceTemplate1.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticPropInferenceTemplate1.ts new file mode 100644 index 0000000000000..05827badf9866 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticPropInferenceTemplate1.ts @@ -0,0 +1,62 @@ +// @strict: true +// @target: esnext + +class MyClass { + static property; + static property2; + + static { + const variable = "something"; + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + } +} + +class MyClass2 { + static accessor property; + static accessor property2; + + static { + const variable = "something"; + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + } +} + +class MyClass3 { + static property; + static property2; + + static { + (() => { + const variable = "something"; + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + })(); + } +} + +class MyClass4 { + static accessor property; + static accessor property2; + + static { + (() => { + const variable = "something"; + + this.property = `foo`; + this.property2 = `foo-${variable}`; + + const localProperty = `foo-${variable}`; + })(); + } +} diff --git a/tests/cases/conformance/classes/classStaticBlock/classStaticPropInitializationInferenceWithElementAccess1.ts b/tests/cases/conformance/classes/classStaticBlock/classStaticPropInitializationInferenceWithElementAccess1.ts new file mode 100644 index 0000000000000..c7bd40e16e649 --- /dev/null +++ b/tests/cases/conformance/classes/classStaticBlock/classStaticPropInitializationInferenceWithElementAccess1.ts @@ -0,0 +1,73 @@ +// @strict: true +// @target: esnext +// @declaration: true + +let seed = 0; + +export class Cls1 { + static x; + static y; + static z; + + static 0; + + static { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + + this[0] = [seed]; + } +} + +export class Cls2 { + static accessor x; + static accessor y; + static accessor z; + + static accessor 0; + + static { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + + this[0] = [seed]; + } +} + +export class Cls3 { + static x; + static y; + static z; + + static 0; + + static { + (() => { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + + this[0] = [seed]; + })(); + } +} + +export class Cls4 { + static accessor x; + static accessor y; + static accessor z; + + static accessor 0; + + static { + (() => { + this["x"] = [seed]; + this["y"] = { seed }; + this["z"] = `${seed}`; + + this[0] = [seed]; + })(); + } +}