diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fcb93c45dc1dd..1547728d9e176 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12188,6 +12188,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { let links = getSymbolLinks(symbol); const originalLinks = links; if (!links.type) { + // Disable all this block to turn off expando assignments for all function expressions const expando = symbol.valueDeclaration && getSymbolOfExpando(symbol.valueDeclaration, /*allowDeclaration*/ false); if (expando) { const merged = mergeJSSymbols(symbol, expando); @@ -37142,7 +37143,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { let name: Expression | BindingName | undefined; let decl: Node | undefined; if (isVariableDeclaration(node.parent) && node.parent.initializer === node) { - if (!isInJSFile(node) && !(isVarConstLike(node.parent) && isFunctionLikeDeclaration(node))) { + if (!isInJSFile(node)) { return undefined; } name = node.parent.name; diff --git a/tests/baselines/reference/annotatedExpandoFunc.errors.txt b/tests/baselines/reference/annotatedExpandoFunc.errors.txt new file mode 100644 index 0000000000000..1215494b4315d --- /dev/null +++ b/tests/baselines/reference/annotatedExpandoFunc.errors.txt @@ -0,0 +1,36 @@ +annotatedExpandoFunc.ts(6,7): error TS2741: Property 'p' is missing in type '() => 1' but required in type 'F'. +annotatedExpandoFunc.ts(8,3): error TS2339: Property 'extra' does not exist on type 'F'. +annotatedExpandoFunc.ts(12,3): error TS2339: Property 'q' does not exist on type '() => number'. +annotatedExpandoFunc.ts(13,20): error TS2339: Property 'q' does not exist on type '() => number'. + + +==== annotatedExpandoFunc.ts (4 errors) ==== + interface F { + (): 1; + p: 2; + } + // disallowed + const f: F = () => 1; + ~ +!!! error TS2741: Property 'p' is missing in type '() => 1' but required in type 'F'. +!!! related TS2728 annotatedExpandoFunc.ts:3:5: 'p' is declared here. + f.p = 2; + f.extra = 3 + ~~~~~ +!!! error TS2339: Property 'extra' does not exist on type 'F'. + const r1 = f() + f.p + // function expressions are still allowed, by analogy with function declarations + const e = () => 4 + e.q = 5 + ~ +!!! error TS2339: Property 'q' does not exist on type '() => number'. + const r2 = e() + e.q + ~ +!!! error TS2339: Property 'q' does not exist on type '() => number'. + // function declarations are still allowed + function g() { + return 6 + } + g.r = 7 + const r3 = g() + g.r + \ No newline at end of file diff --git a/tests/baselines/reference/annotatedExpandoFunc.symbols b/tests/baselines/reference/annotatedExpandoFunc.symbols new file mode 100644 index 0000000000000..c333648032733 --- /dev/null +++ b/tests/baselines/reference/annotatedExpandoFunc.symbols @@ -0,0 +1,60 @@ +//// [tests/cases/conformance/salsa/annotatedExpandoFunc.ts] //// + +=== annotatedExpandoFunc.ts === +interface F { +>F : Symbol(F, Decl(annotatedExpandoFunc.ts, 0, 0)) + + (): 1; + p: 2; +>p : Symbol(F.p, Decl(annotatedExpandoFunc.ts, 1, 10)) +} +// disallowed +const f: F = () => 1; +>f : Symbol(f, Decl(annotatedExpandoFunc.ts, 5, 5), Decl(annotatedExpandoFunc.ts, 5, 21), Decl(annotatedExpandoFunc.ts, 6, 8)) +>F : Symbol(F, Decl(annotatedExpandoFunc.ts, 0, 0)) + +f.p = 2; +>f.p : Symbol(F.p, Decl(annotatedExpandoFunc.ts, 1, 10)) +>f : Symbol(f, Decl(annotatedExpandoFunc.ts, 5, 5), Decl(annotatedExpandoFunc.ts, 5, 21), Decl(annotatedExpandoFunc.ts, 6, 8)) +>p : Symbol(F.p, Decl(annotatedExpandoFunc.ts, 1, 10)) + +f.extra = 3 +>f : Symbol(f, Decl(annotatedExpandoFunc.ts, 5, 5), Decl(annotatedExpandoFunc.ts, 5, 21), Decl(annotatedExpandoFunc.ts, 6, 8)) + +const r1 = f() + f.p +>r1 : Symbol(r1, Decl(annotatedExpandoFunc.ts, 8, 5)) +>f : Symbol(f, Decl(annotatedExpandoFunc.ts, 5, 5), Decl(annotatedExpandoFunc.ts, 5, 21), Decl(annotatedExpandoFunc.ts, 6, 8)) +>f.p : Symbol(F.p, Decl(annotatedExpandoFunc.ts, 1, 10)) +>f : Symbol(f, Decl(annotatedExpandoFunc.ts, 5, 5), Decl(annotatedExpandoFunc.ts, 5, 21), Decl(annotatedExpandoFunc.ts, 6, 8)) +>p : Symbol(F.p, Decl(annotatedExpandoFunc.ts, 1, 10)) + +// function expressions are still allowed, by analogy with function declarations +const e = () => 4 +>e : Symbol(e, Decl(annotatedExpandoFunc.ts, 10, 5), Decl(annotatedExpandoFunc.ts, 10, 17)) + +e.q = 5 +>e : Symbol(e, Decl(annotatedExpandoFunc.ts, 10, 5), Decl(annotatedExpandoFunc.ts, 10, 17)) + +const r2 = e() + e.q +>r2 : Symbol(r2, Decl(annotatedExpandoFunc.ts, 12, 5)) +>e : Symbol(e, Decl(annotatedExpandoFunc.ts, 10, 5), Decl(annotatedExpandoFunc.ts, 10, 17)) +>e : Symbol(e, Decl(annotatedExpandoFunc.ts, 10, 5), Decl(annotatedExpandoFunc.ts, 10, 17)) + +// function declarations are still allowed +function g() { +>g : Symbol(g, Decl(annotatedExpandoFunc.ts, 12, 20), Decl(annotatedExpandoFunc.ts, 16, 1)) + + return 6 +} +g.r = 7 +>g.r : Symbol(g.r, Decl(annotatedExpandoFunc.ts, 16, 1)) +>g : Symbol(g, Decl(annotatedExpandoFunc.ts, 12, 20), Decl(annotatedExpandoFunc.ts, 16, 1)) +>r : Symbol(g.r, Decl(annotatedExpandoFunc.ts, 16, 1)) + +const r3 = g() + g.r +>r3 : Symbol(r3, Decl(annotatedExpandoFunc.ts, 18, 5)) +>g : Symbol(g, Decl(annotatedExpandoFunc.ts, 12, 20), Decl(annotatedExpandoFunc.ts, 16, 1)) +>g.r : Symbol(g.r, Decl(annotatedExpandoFunc.ts, 16, 1)) +>g : Symbol(g, Decl(annotatedExpandoFunc.ts, 12, 20), Decl(annotatedExpandoFunc.ts, 16, 1)) +>r : Symbol(g.r, Decl(annotatedExpandoFunc.ts, 16, 1)) + diff --git a/tests/baselines/reference/annotatedExpandoFunc.types b/tests/baselines/reference/annotatedExpandoFunc.types new file mode 100644 index 0000000000000..45b5707d6a9df --- /dev/null +++ b/tests/baselines/reference/annotatedExpandoFunc.types @@ -0,0 +1,132 @@ +//// [tests/cases/conformance/salsa/annotatedExpandoFunc.ts] //// + +=== annotatedExpandoFunc.ts === +interface F { + (): 1; + p: 2; +>p : 2 +> : ^ +} +// disallowed +const f: F = () => 1; +>f : F +> : ^ +>() => 1 : () => 1 +> : ^^^^^^^ +>1 : 1 +> : ^ + +f.p = 2; +>f.p = 2 : 2 +> : ^ +>f.p : 2 +> : ^ +>f : F +> : ^ +>p : 2 +> : ^ +>2 : 2 +> : ^ + +f.extra = 3 +>f.extra = 3 : 3 +> : ^ +>f.extra : any +> : ^^^ +>f : F +> : ^ +>extra : any +> : ^^^ +>3 : 3 +> : ^ + +const r1 = f() + f.p +>r1 : number +> : ^^^^^^ +>f() + f.p : number +> : ^^^^^^ +>f() : 1 +> : ^ +>f : F +> : ^ +>f.p : 2 +> : ^ +>f : F +> : ^ +>p : 2 +> : ^ + +// function expressions are still allowed, by analogy with function declarations +const e = () => 4 +>e : () => number +> : ^^^^^^^^^^^^ +>() => 4 : () => number +> : ^^^^^^^^^^^^ +>4 : 4 +> : ^ + +e.q = 5 +>e.q = 5 : 5 +> : ^ +>e.q : any +> : ^^^ +>e : () => number +> : ^^^^^^^^^^^^ +>q : any +> : ^^^ +>5 : 5 +> : ^ + +const r2 = e() + e.q +>r2 : any +> : ^^^ +>e() + e.q : any +> : ^^^ +>e() : number +> : ^^^^^^ +>e : () => number +> : ^^^^^^^^^^^^ +>e.q : any +> : ^^^ +>e : () => number +> : ^^^^^^^^^^^^ +>q : any +> : ^^^ + +// function declarations are still allowed +function g() { +>g : typeof g +> : ^^^^^^^^ + + return 6 +>6 : 6 +> : ^ +} +g.r = 7 +>g.r = 7 : 7 +> : ^ +>g.r : number +> : ^^^^^^ +>g : typeof g +> : ^^^^^^^^ +>r : number +> : ^^^^^^ +>7 : 7 +> : ^ + +const r3 = g() + g.r +>r3 : number +> : ^^^^^^ +>g() + g.r : number +> : ^^^^^^ +>g() : number +> : ^^^^^^ +>g : typeof g +> : ^^^^^^^^ +>g.r : number +> : ^^^^^^ +>g : typeof g +> : ^^^^^^^^ +>r : number +> : ^^^^^^ + diff --git a/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.errors.txt b/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.errors.txt new file mode 100644 index 0000000000000..3a123c74c8448 --- /dev/null +++ b/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.errors.txt @@ -0,0 +1,20 @@ +declarationEmitExpandoWithGenericConstraint.ts(14,7): error TS2339: Property 'zero' does not exist on type '(x: number, y: number) => Point'. + + +==== declarationEmitExpandoWithGenericConstraint.ts (1 errors) ==== + export interface Point { + readonly x: number; + readonly y: number; + } + + export interface Rect

{ + readonly a: p; + readonly b: p; + } + + export const Point = (x: number, y: number): Point => ({ x, y }); + export const Rect =

(a: p, b: p): Rect

=> ({ a, b }); + + Point.zero = (): Point => Point(0, 0); + ~~~~ +!!! error TS2339: Property 'zero' does not exist on type '(x: number, y: number) => Point'. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.js b/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.js index cc0d1facf9b73..b66a49708881f 100644 --- a/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.js +++ b/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.js @@ -36,8 +36,5 @@ export interface Rect

{ readonly a: p; readonly b: p; } -export declare const Point: { - (x: number, y: number): Point; - zero(): Point; -}; +export declare const Point: (x: number, y: number) => Point; export declare const Rect:

(a: p, b: p) => Rect

; diff --git a/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.symbols b/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.symbols index 9e62560cb9935..ec0ed9967293b 100644 --- a/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.symbols +++ b/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.symbols @@ -47,9 +47,7 @@ export const Rect =

(a: p, b: p): Rect

=> ({ a, b }); >b : Symbol(b, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 67)) Point.zero = (): Point => Point(0, 0); ->Point.zero : Symbol(Point.zero, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73)) >Point : Symbol(Point, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 0), Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 12), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73)) ->zero : Symbol(Point.zero, Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73)) >Point : Symbol(Point, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 0), Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 12), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73)) >Point : Symbol(Point, Decl(declarationEmitExpandoWithGenericConstraint.ts, 0, 0), Decl(declarationEmitExpandoWithGenericConstraint.ts, 10, 12), Decl(declarationEmitExpandoWithGenericConstraint.ts, 11, 73)) diff --git a/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.types b/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.types index e57c9a4e2c90e..75f35ccbc4aeb 100644 --- a/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.types +++ b/tests/baselines/reference/declarationEmitExpandoWithGenericConstraint.types @@ -22,10 +22,10 @@ export interface Rect

{ } export const Point = (x: number, y: number): Point => ({ x, y }); ->Point : { (x: number, y: number): Point; zero(): Point; } -> : ^^^ ^^ ^^ ^^ ^^^ ^^^^^^^^^^ ^^^ ->(x: number, y: number): Point => ({ x, y }) : { (x: number, y: number): Point; zero(): Point; } -> : ^^^ ^^ ^^ ^^ ^^^ ^^^^^^^^^^ ^^^ +>Point : (x: number, y: number) => Point +> : ^ ^^ ^^ ^^ ^^^^^ +>(x: number, y: number): Point => ({ x, y }) : (x: number, y: number) => Point +> : ^ ^^ ^^ ^^ ^^^^^ >x : number > : ^^^^^^ >y : number @@ -60,18 +60,18 @@ export const Rect =

(a: p, b: p): Rect

=> ({ a, b }); Point.zero = (): Point => Point(0, 0); >Point.zero = (): Point => Point(0, 0) : () => Point > : ^^^^^^ ->Point.zero : () => Point -> : ^^^^^^ ->Point : { (x: number, y: number): Point; zero(): Point; } -> : ^^^ ^^ ^^ ^^ ^^^ ^^^^^^^^^^ ^^^ ->zero : () => Point -> : ^^^^^^ +>Point.zero : any +> : ^^^ +>Point : (x: number, y: number) => Point +> : ^ ^^ ^^ ^^ ^^^^^ +>zero : any +> : ^^^ >(): Point => Point(0, 0) : () => Point > : ^^^^^^ >Point(0, 0) : Point > : ^^^^^ ->Point : { (x: number, y: number): Point; zero(): Point; } -> : ^^^ ^^ ^^ ^^ ^^^ ^^^^^^^^^^ ^^^ +>Point : (x: number, y: number) => Point +> : ^ ^^ ^^ ^^ ^^^^^ >0 : 0 > : ^ >0 : 0 diff --git a/tests/baselines/reference/declarationEmitLateBoundAssignments2.errors.txt b/tests/baselines/reference/declarationEmitLateBoundAssignments2.errors.txt new file mode 100644 index 0000000000000..f5b95d848dce0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitLateBoundAssignments2.errors.txt @@ -0,0 +1,96 @@ +declarationEmitLateBoundAssignments2.ts(40,1): error TS7053: Element implicitly has an 'any' type because expression of type '"B"' can't be used to index type '() => void'. + Property 'B' does not exist on type '() => void'. +declarationEmitLateBoundAssignments2.ts(46,1): error TS7053: Element implicitly has an 'any' type because expression of type '77' can't be used to index type '() => void'. + Property '77' does not exist on type '() => void'. +declarationEmitLateBoundAssignments2.ts(52,1): error TS7053: Element implicitly has an 'any' type because expression of type '"101"' can't be used to index type '() => void'. + Property '101' does not exist on type '() => void'. +declarationEmitLateBoundAssignments2.ts(58,1): error TS7053: Element implicitly has an 'any' type because expression of type '"qwe rty"' can't be used to index type '() => void'. + Property 'qwe rty' does not exist on type '() => void'. +declarationEmitLateBoundAssignments2.ts(64,1): error TS7053: Element implicitly has an 'any' type because expression of type '"🤪"' can't be used to index type '() => void'. + Property '🤪' does not exist on type '() => void'. + + +==== declarationEmitLateBoundAssignments2.ts (5 errors) ==== + // https://github.com/microsoft/TypeScript/issues/54811 + + const c = "C" + const num = 1 + const numStr = "10" + const withWhitespace = "foo bar" + const emoji = "🤷‍♂️" + + export function decl() {} + decl["B"] = 'foo' + + export function decl2() {} + decl2[c] = 0 + + export function decl3() {} + decl3[77] = 0 + + export function decl4() {} + decl4[num] = 0 + + export function decl5() {} + decl5["101"] = 0 + + export function decl6() {} + decl6[numStr] = 0 + + export function decl7() {} + decl7["qwe rty"] = 0 + + export function decl8() {} + decl8[withWhitespace] = 0 + + export function decl9() {} + decl9["🤪"] = 0 + + export function decl10() {} + decl10[emoji] = 0 + + export const arrow = () => {} + arrow["B"] = 'bar' + ~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"B"' can't be used to index type '() => void'. +!!! error TS7053: Property 'B' does not exist on type '() => void'. + + export const arrow2 = () => {} + arrow2[c] = 100 + + export const arrow3 = () => {} + arrow3[77] = 0 + ~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '77' can't be used to index type '() => void'. +!!! error TS7053: Property '77' does not exist on type '() => void'. + + export const arrow4 = () => {} + arrow4[num] = 0 + + export const arrow5 = () => {} + arrow5["101"] = 0 + ~~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"101"' can't be used to index type '() => void'. +!!! error TS7053: Property '101' does not exist on type '() => void'. + + export const arrow6 = () => {} + arrow6[numStr] = 0 + + export const arrow7 = () => {} + arrow7["qwe rty"] = 0 + ~~~~~~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"qwe rty"' can't be used to index type '() => void'. +!!! error TS7053: Property 'qwe rty' does not exist on type '() => void'. + + export const arrow8 = () => {} + arrow8[withWhitespace] = 0 + + export const arrow9 = () => {} + arrow9["🤪"] = 0 + ~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"🤪"' can't be used to index type '() => void'. +!!! error TS7053: Property '🤪' does not exist on type '() => void'. + + export const arrow10 = () => {} + arrow10[emoji] = 0 + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitLateBoundAssignments2.js b/tests/baselines/reference/declarationEmitLateBoundAssignments2.js index 1b150435028d8..9ae60197eea9e 100644 --- a/tests/baselines/reference/declarationEmitLateBoundAssignments2.js +++ b/tests/baselines/reference/declarationEmitLateBoundAssignments2.js @@ -144,42 +144,27 @@ export declare function decl9(): void; export declare namespace decl9 { } export declare function decl10(): void; export declare namespace decl10 { } -export declare const arrow: { - (): void; - B: string; -}; +export declare const arrow: () => void; export declare const arrow2: { (): void; C: number; }; -export declare const arrow3: { - (): void; - 77: number; -}; +export declare const arrow3: () => void; export declare const arrow4: { (): void; 1: number; }; -export declare const arrow5: { - (): void; - "101": number; -}; +export declare const arrow5: () => void; export declare const arrow6: { (): void; "10": number; }; -export declare const arrow7: { - (): void; - "qwe rty": number; -}; +export declare const arrow7: () => void; export declare const arrow8: { (): void; "foo bar": number; }; -export declare const arrow9: { - (): void; - "\uD83E\uDD2A": number; -}; +export declare const arrow9: () => void; export declare const arrow10: { (): void; "\uD83E\uDD37\u200D\u2642\uFE0F": number; diff --git a/tests/baselines/reference/declarationEmitLateBoundAssignments2.symbols b/tests/baselines/reference/declarationEmitLateBoundAssignments2.symbols index b17cea5a9969d..3b8c3e77de618 100644 --- a/tests/baselines/reference/declarationEmitLateBoundAssignments2.symbols +++ b/tests/baselines/reference/declarationEmitLateBoundAssignments2.symbols @@ -93,7 +93,6 @@ export const arrow = () => {} arrow["B"] = 'bar' >arrow : Symbol(arrow, Decl(declarationEmitLateBoundAssignments2.ts, 38, 12), Decl(declarationEmitLateBoundAssignments2.ts, 38, 29)) ->"B" : Symbol(arrow["B"], Decl(declarationEmitLateBoundAssignments2.ts, 38, 29)) export const arrow2 = () => {} >arrow2 : Symbol(arrow2, Decl(declarationEmitLateBoundAssignments2.ts, 41, 12), Decl(declarationEmitLateBoundAssignments2.ts, 41, 30)) @@ -107,7 +106,6 @@ export const arrow3 = () => {} arrow3[77] = 0 >arrow3 : Symbol(arrow3, Decl(declarationEmitLateBoundAssignments2.ts, 44, 12), Decl(declarationEmitLateBoundAssignments2.ts, 44, 30)) ->77 : Symbol(arrow3[77], Decl(declarationEmitLateBoundAssignments2.ts, 44, 30)) export const arrow4 = () => {} >arrow4 : Symbol(arrow4, Decl(declarationEmitLateBoundAssignments2.ts, 47, 12), Decl(declarationEmitLateBoundAssignments2.ts, 47, 30)) @@ -121,7 +119,6 @@ export const arrow5 = () => {} arrow5["101"] = 0 >arrow5 : Symbol(arrow5, Decl(declarationEmitLateBoundAssignments2.ts, 50, 12), Decl(declarationEmitLateBoundAssignments2.ts, 50, 30)) ->"101" : Symbol(arrow5["101"], Decl(declarationEmitLateBoundAssignments2.ts, 50, 30)) export const arrow6 = () => {} >arrow6 : Symbol(arrow6, Decl(declarationEmitLateBoundAssignments2.ts, 53, 12), Decl(declarationEmitLateBoundAssignments2.ts, 53, 30)) @@ -135,7 +132,6 @@ export const arrow7 = () => {} arrow7["qwe rty"] = 0 >arrow7 : Symbol(arrow7, Decl(declarationEmitLateBoundAssignments2.ts, 56, 12), Decl(declarationEmitLateBoundAssignments2.ts, 56, 30)) ->"qwe rty" : Symbol(arrow7["qwe rty"], Decl(declarationEmitLateBoundAssignments2.ts, 56, 30)) export const arrow8 = () => {} >arrow8 : Symbol(arrow8, Decl(declarationEmitLateBoundAssignments2.ts, 59, 12), Decl(declarationEmitLateBoundAssignments2.ts, 59, 30)) @@ -149,7 +145,6 @@ export const arrow9 = () => {} arrow9["🤪"] = 0 >arrow9 : Symbol(arrow9, Decl(declarationEmitLateBoundAssignments2.ts, 62, 12), Decl(declarationEmitLateBoundAssignments2.ts, 62, 30)) ->"🤪" : Symbol(arrow9["\uD83E\uDD2A"], Decl(declarationEmitLateBoundAssignments2.ts, 62, 30)) export const arrow10 = () => {} >arrow10 : Symbol(arrow10, Decl(declarationEmitLateBoundAssignments2.ts, 65, 12), Decl(declarationEmitLateBoundAssignments2.ts, 65, 31)) diff --git a/tests/baselines/reference/declarationEmitLateBoundAssignments2.types b/tests/baselines/reference/declarationEmitLateBoundAssignments2.types index 72e3e7bd20533..75776d68df37b 100644 --- a/tests/baselines/reference/declarationEmitLateBoundAssignments2.types +++ b/tests/baselines/reference/declarationEmitLateBoundAssignments2.types @@ -194,18 +194,18 @@ decl10[emoji] = 0 > : ^ export const arrow = () => {} ->arrow : { (): void; B: string; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^ ->() => {} : { (): void; B: string; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>arrow : () => void +> : ^^^^^^^^^^ +>() => {} : () => void +> : ^^^^^^^^^^ arrow["B"] = 'bar' >arrow["B"] = 'bar' : "bar" > : ^^^^^ ->arrow["B"] : string -> : ^^^^^^ ->arrow : { (): void; B: string; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>arrow["B"] : any +> : ^^^ +>arrow : () => void +> : ^^^^^^^^^^ >"B" : "B" > : ^^^ >'bar' : "bar" @@ -230,18 +230,18 @@ arrow2[c] = 100 > : ^^^ export const arrow3 = () => {} ->arrow3 : { (): void; 77: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^ ->() => {} : { (): void; 77: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>arrow3 : () => void +> : ^^^^^^^^^^ +>() => {} : () => void +> : ^^^^^^^^^^ arrow3[77] = 0 >arrow3[77] = 0 : 0 > : ^ ->arrow3[77] : number -> : ^^^^^^ ->arrow3 : { (): void; 77: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^ +>arrow3[77] : any +> : ^^^ +>arrow3 : () => void +> : ^^^^^^^^^^ >77 : 77 > : ^^ >0 : 0 @@ -266,18 +266,18 @@ arrow4[num] = 0 > : ^ export const arrow5 = () => {} ->arrow5 : { (): void; "101": number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->() => {} : { (): void; "101": number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>arrow5 : () => void +> : ^^^^^^^^^^ +>() => {} : () => void +> : ^^^^^^^^^^ arrow5["101"] = 0 >arrow5["101"] = 0 : 0 > : ^ ->arrow5["101"] : number -> : ^^^^^^ ->arrow5 : { (): void; "101": number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>arrow5["101"] : any +> : ^^^ +>arrow5 : () => void +> : ^^^^^^^^^^ >"101" : "101" > : ^^^^^ >0 : 0 @@ -302,18 +302,18 @@ arrow6[numStr] = 0 > : ^ export const arrow7 = () => {} ->arrow7 : { (): void; "qwe rty": number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->() => {} : { (): void; "qwe rty": number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>arrow7 : () => void +> : ^^^^^^^^^^ +>() => {} : () => void +> : ^^^^^^^^^^ arrow7["qwe rty"] = 0 >arrow7["qwe rty"] = 0 : 0 > : ^ ->arrow7["qwe rty"] : number -> : ^^^^^^ ->arrow7 : { (): void; "qwe rty": number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>arrow7["qwe rty"] : any +> : ^^^ +>arrow7 : () => void +> : ^^^^^^^^^^ >"qwe rty" : "qwe rty" > : ^^^^^^^^^ >0 : 0 @@ -338,18 +338,18 @@ arrow8[withWhitespace] = 0 > : ^ export const arrow9 = () => {} ->arrow9 : { (): void; "\uD83E\uDD2A": number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->() => {} : { (): void; "\uD83E\uDD2A": number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>arrow9 : () => void +> : ^^^^^^^^^^ +>() => {} : () => void +> : ^^^^^^^^^^ arrow9["🤪"] = 0 >arrow9["🤪"] = 0 : 0 > : ^ ->arrow9["🤪"] : number -> : ^^^^^^ ->arrow9 : { (): void; "\uD83E\uDD2A": number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>arrow9["🤪"] : any +> : ^^^ +>arrow9 : () => void +> : ^^^^^^^^^^ >"🤪" : "🤪" > : ^^^^ >0 : 0 diff --git a/tests/baselines/reference/expandoFunctionBlockShadowing.errors.txt b/tests/baselines/reference/expandoFunctionBlockShadowing.errors.txt new file mode 100644 index 0000000000000..0eeacd0468736 --- /dev/null +++ b/tests/baselines/reference/expandoFunctionBlockShadowing.errors.txt @@ -0,0 +1,28 @@ +expandoFunctionBlockShadowing.ts(14,5): error TS2339: Property 'test' does not exist on type '() => void'. +expandoFunctionBlockShadowing.ts(17,9): error TS2741: Property 'test' is missing in type '() => void' but required in type '{ (): void; test: number; }'. + + +==== expandoFunctionBlockShadowing.ts (2 errors) ==== + // https://github.com/microsoft/TypeScript/issues/56538 + + export function X() {} + if (Math.random()) { + const X: { test?: any } = {}; + X.test = 1; + } + + export function Y() {} + Y.test = "foo"; + const aliasTopY = Y; + if (Math.random()) { + const Y = function Y() {} + Y.test = 42; + ~~~~ +!!! error TS2339: Property 'test' does not exist on type '() => void'. + + const topYcheck: { (): void; test: string } = aliasTopY; + const blockYcheck: { (): void; test: number } = Y; + ~~~~~~~~~~~ +!!! error TS2741: Property 'test' is missing in type '() => void' but required in type '{ (): void; test: number; }'. +!!! related TS2728 expandoFunctionBlockShadowing.ts:17:34: 'test' is declared here. + } \ No newline at end of file diff --git a/tests/baselines/reference/expandoFunctionBlockShadowing.symbols b/tests/baselines/reference/expandoFunctionBlockShadowing.symbols index d4e7f017fbcad..734a2acbc3222 100644 --- a/tests/baselines/reference/expandoFunctionBlockShadowing.symbols +++ b/tests/baselines/reference/expandoFunctionBlockShadowing.symbols @@ -43,9 +43,7 @@ if (Math.random()) { >Y : Symbol(Y, Decl(expandoFunctionBlockShadowing.ts, 12, 11)) Y.test = 42; ->Y.test : Symbol(Y.test, Decl(expandoFunctionBlockShadowing.ts, 12, 27)) >Y : Symbol(Y, Decl(expandoFunctionBlockShadowing.ts, 12, 7)) ->test : Symbol(Y.test, Decl(expandoFunctionBlockShadowing.ts, 12, 27)) const topYcheck: { (): void; test: string } = aliasTopY; >topYcheck : Symbol(topYcheck, Decl(expandoFunctionBlockShadowing.ts, 15, 7)) diff --git a/tests/baselines/reference/expandoFunctionBlockShadowing.types b/tests/baselines/reference/expandoFunctionBlockShadowing.types index 1c857af946650..c982dbf22c7c0 100644 --- a/tests/baselines/reference/expandoFunctionBlockShadowing.types +++ b/tests/baselines/reference/expandoFunctionBlockShadowing.types @@ -21,6 +21,7 @@ if (Math.random()) { >X : { test?: any; } > : ^^^^^^^^^ ^^^ >test : any +> : ^^^ >{} : {} > : ^^ @@ -28,6 +29,7 @@ if (Math.random()) { >X.test = 1 : 1 > : ^ >X.test : any +> : ^^^ >X : { test?: any; } > : ^^^^^^^^^ ^^^ >test : any @@ -69,22 +71,22 @@ if (Math.random()) { > : ^^^^^^ const Y = function Y() {} ->Y : { (): void; test: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->function Y() {} : { (): void; test: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->Y : { (): void; test: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Y : () => void +> : ^^^^^^^^^^ +>function Y() {} : () => void +> : ^^^^^^^^^^ +>Y : () => void +> : ^^^^^^^^^^ Y.test = 42; >Y.test = 42 : 42 > : ^^ ->Y.test : number -> : ^^^^^^ ->Y : { (): void; test: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->test : number -> : ^^^^^^ +>Y.test : any +> : ^^^ +>Y : () => void +> : ^^^^^^^^^^ +>test : any +> : ^^^ >42 : 42 > : ^^ @@ -101,6 +103,6 @@ if (Math.random()) { > : ^^^^^^ ^^^^^^^^ ^^^ >test : number > : ^^^^^^ ->Y : { (): void; test: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Y : () => void +> : ^^^^^^^^^^ } diff --git a/tests/baselines/reference/expandoFunctionContextualTypes.types b/tests/baselines/reference/expandoFunctionContextualTypes.types index e1129825f3065..9d6524d235654 100644 --- a/tests/baselines/reference/expandoFunctionContextualTypes.types +++ b/tests/baselines/reference/expandoFunctionContextualTypes.types @@ -17,8 +17,8 @@ interface StatelessComponent

{ const MyComponent: StatelessComponent = () => null as any; >MyComponent : StatelessComponent > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->() => null as any : { (): any; defaultProps: Partial; } -> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>() => null as any : () => any +> : ^^^^^^ >null as any : any MyComponent.defaultProps = { diff --git a/tests/baselines/reference/goToDefinitionPropertyAssignment.baseline.jsonc b/tests/baselines/reference/goToDefinitionPropertyAssignment.baseline.jsonc index 11e6753b984db..8fd8d3d90d16d 100644 --- a/tests/baselines/reference/goToDefinitionPropertyAssignment.baseline.jsonc +++ b/tests/baselines/reference/goToDefinitionPropertyAssignment.baseline.jsonc @@ -25,21 +25,8 @@ // === goToDefinition === // === /tests/cases/fourslash/goToDefinitionPropertyAssignment.ts === // export const Component = () => { return "OK"} -// <|Component.[|displayName|]|> = 'Component' +// Component.displayName = 'Component' // // Component // -// Component./*GOTO DEF*/displayName - - // === Details === - [ - { - "kind": "property", - "name": "displayName", - "containerName": "Component", - "isLocal": true, - "isAmbient": false, - "unverified": false, - "failedAliasResolution": false - } - ] \ No newline at end of file +// Component./*GOTO DEF*/displayName \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrors.errors.txt b/tests/baselines/reference/isolatedDeclarationErrors.errors.txt index 2bc5caf198c2e..8190b1984a783 100644 --- a/tests/baselines/reference/isolatedDeclarationErrors.errors.txt +++ b/tests/baselines/reference/isolatedDeclarationErrors.errors.txt @@ -1,7 +1,7 @@ isolatedDeclarationErrors.ts(2,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. -isolatedDeclarationErrors.ts(5,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. +isolatedDeclarationErrors.ts(5,24): error TS2339: Property 'a' does not exist on type '() => void'. isolatedDeclarationErrors.ts(7,30): error TS9007: Function must have an explicit return type annotation with --isolatedDeclarations. -isolatedDeclarationErrors.ts(8,1): error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. +isolatedDeclarationErrors.ts(8,22): error TS2339: Property 'a' does not exist on type '() => void'. ==== isolatedDeclarationErrors.ts (4 errors) ==== @@ -12,8 +12,8 @@ isolatedDeclarationErrors.ts(8,1): error TS9023: Assigning properties to functio const errorOnAssignmentBelow = (): void => {} errorOnAssignmentBelow.a = ""; - ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. + ~ +!!! error TS2339: Property 'a' does not exist on type '() => void'. const errorOnMissingReturn = () => {} ~~~~~~~~ @@ -21,6 +21,6 @@ isolatedDeclarationErrors.ts(8,1): error TS9023: Assigning properties to functio !!! related TS9027 isolatedDeclarationErrors.ts:7:7: Add a type annotation to the variable errorOnMissingReturn. !!! related TS9030 isolatedDeclarationErrors.ts:7:30: Add a return type to the function expression. errorOnMissingReturn.a = ""; - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9023: Assigning properties to functions without declaring them is not supported with --isolatedDeclarations. Add an explicit declaration for the properties assigned to this function. + ~ +!!! error TS2339: Property 'a' does not exist on type '() => void'. \ No newline at end of file diff --git a/tests/baselines/reference/isolatedDeclarationErrors.symbols b/tests/baselines/reference/isolatedDeclarationErrors.symbols index 3bb2b757c3a56..e4c96127fff1a 100644 --- a/tests/baselines/reference/isolatedDeclarationErrors.symbols +++ b/tests/baselines/reference/isolatedDeclarationErrors.symbols @@ -13,15 +13,11 @@ const errorOnAssignmentBelow = (): void => {} >errorOnAssignmentBelow : Symbol(errorOnAssignmentBelow, Decl(isolatedDeclarationErrors.ts, 3, 5), Decl(isolatedDeclarationErrors.ts, 3, 45)) errorOnAssignmentBelow.a = ""; ->errorOnAssignmentBelow.a : Symbol(errorOnAssignmentBelow.a, Decl(isolatedDeclarationErrors.ts, 3, 45)) >errorOnAssignmentBelow : Symbol(errorOnAssignmentBelow, Decl(isolatedDeclarationErrors.ts, 3, 5), Decl(isolatedDeclarationErrors.ts, 3, 45)) ->a : Symbol(errorOnAssignmentBelow.a, Decl(isolatedDeclarationErrors.ts, 3, 45)) const errorOnMissingReturn = () => {} >errorOnMissingReturn : Symbol(errorOnMissingReturn, Decl(isolatedDeclarationErrors.ts, 6, 5), Decl(isolatedDeclarationErrors.ts, 6, 37)) errorOnMissingReturn.a = ""; ->errorOnMissingReturn.a : Symbol(errorOnMissingReturn.a, Decl(isolatedDeclarationErrors.ts, 6, 37)) >errorOnMissingReturn : Symbol(errorOnMissingReturn, Decl(isolatedDeclarationErrors.ts, 6, 5), Decl(isolatedDeclarationErrors.ts, 6, 37)) ->a : Symbol(errorOnMissingReturn.a, Decl(isolatedDeclarationErrors.ts, 6, 37)) diff --git a/tests/baselines/reference/isolatedDeclarationErrors.types b/tests/baselines/reference/isolatedDeclarationErrors.types index d311928409fc7..8177a9f43f076 100644 --- a/tests/baselines/reference/isolatedDeclarationErrors.types +++ b/tests/baselines/reference/isolatedDeclarationErrors.types @@ -18,38 +18,38 @@ errorOnAssignmentBelowDecl.a = ""; > : ^^ const errorOnAssignmentBelow = (): void => {} ->errorOnAssignmentBelow : { (): void; a: string; } -> : ^^^^^^ ^^^^^^^^^^^^^^ ->(): void => {} : { (): void; a: string; } -> : ^^^^^^ ^^^^^^^^^^^^^^ +>errorOnAssignmentBelow : () => void +> : ^^^^^^ +>(): void => {} : () => void +> : ^^^^^^ errorOnAssignmentBelow.a = ""; >errorOnAssignmentBelow.a = "" : "" > : ^^ ->errorOnAssignmentBelow.a : string -> : ^^^^^^ ->errorOnAssignmentBelow : { (): void; a: string; } -> : ^^^^^^ ^^^^^^^^^^^^^^ ->a : string -> : ^^^^^^ +>errorOnAssignmentBelow.a : any +> : ^^^ +>errorOnAssignmentBelow : () => void +> : ^^^^^^ +>a : any +> : ^^^ >"" : "" > : ^^ const errorOnMissingReturn = () => {} ->errorOnMissingReturn : { (): void; a: string; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^ ->() => {} : { (): void; a: string; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>errorOnMissingReturn : () => void +> : ^^^^^^^^^^ +>() => {} : () => void +> : ^^^^^^^^^^ errorOnMissingReturn.a = ""; >errorOnMissingReturn.a = "" : "" > : ^^ ->errorOnMissingReturn.a : string -> : ^^^^^^ ->errorOnMissingReturn : { (): void; a: string; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^ ->a : string -> : ^^^^^^ +>errorOnMissingReturn.a : any +> : ^^^ +>errorOnMissingReturn : () => void +> : ^^^^^^^^^^ +>a : any +> : ^^^ >"" : "" > : ^^ diff --git a/tests/baselines/reference/propertyAssignmentUseParentType1.errors.txt b/tests/baselines/reference/propertyAssignmentUseParentType1.errors.txt new file mode 100644 index 0000000000000..6511f1328000a --- /dev/null +++ b/tests/baselines/reference/propertyAssignmentUseParentType1.errors.txt @@ -0,0 +1,28 @@ +propertyAssignmentUseParentType1.ts(5,14): error TS2741: Property 'num' is missing in type '() => true' but required in type 'N'. +propertyAssignmentUseParentType1.ts(8,14): error TS2741: Property 'nun' is missing in type '() => true' but required in type '{ (): boolean; nun: 456; }'. +propertyAssignmentUseParentType1.ts(13,13): error TS2339: Property 'extra' does not exist on type '() => boolean'. + + +==== propertyAssignmentUseParentType1.ts (3 errors) ==== + interface N { + (): boolean + num: 123; + } + export const interfaced: N = () => true; + ~~~~~~~~~~ +!!! error TS2741: Property 'num' is missing in type '() => true' but required in type 'N'. +!!! related TS2728 propertyAssignmentUseParentType1.ts:3:5: 'num' is declared here. + interfaced.num = 123; + + export const inlined: { (): boolean; nun: 456 } = () => true; + ~~~~~~~ +!!! error TS2741: Property 'nun' is missing in type '() => true' but required in type '{ (): boolean; nun: 456; }'. +!!! related TS2728 propertyAssignmentUseParentType1.ts:8:38: 'nun' is declared here. + inlined.nun = 456; + + export const ignoreJsdoc = () => true; + /** @type {string} make sure to ignore jsdoc! */ + ignoreJsdoc.extra = 111 + ~~~~~ +!!! error TS2339: Property 'extra' does not exist on type '() => boolean'. + \ No newline at end of file diff --git a/tests/baselines/reference/propertyAssignmentUseParentType1.symbols b/tests/baselines/reference/propertyAssignmentUseParentType1.symbols index 5f69680571440..6fb3613238b1f 100644 --- a/tests/baselines/reference/propertyAssignmentUseParentType1.symbols +++ b/tests/baselines/reference/propertyAssignmentUseParentType1.symbols @@ -31,7 +31,5 @@ export const ignoreJsdoc = () => true; /** @type {string} make sure to ignore jsdoc! */ ignoreJsdoc.extra = 111 ->ignoreJsdoc.extra : Symbol(ignoreJsdoc.extra, Decl(propertyAssignmentUseParentType1.ts, 10, 38)) >ignoreJsdoc : Symbol(ignoreJsdoc, Decl(propertyAssignmentUseParentType1.ts, 10, 12), Decl(propertyAssignmentUseParentType1.ts, 10, 38)) ->extra : Symbol(ignoreJsdoc.extra, Decl(propertyAssignmentUseParentType1.ts, 10, 38)) diff --git a/tests/baselines/reference/propertyAssignmentUseParentType1.types b/tests/baselines/reference/propertyAssignmentUseParentType1.types index bb347594d8a0c..b8fa6417def64 100644 --- a/tests/baselines/reference/propertyAssignmentUseParentType1.types +++ b/tests/baselines/reference/propertyAssignmentUseParentType1.types @@ -10,8 +10,8 @@ interface N { export const interfaced: N = () => true; >interfaced : N > : ^ ->() => true : { (): true; num: 123; } -> : ^^^^^^^^^^^^^^^^^^^^^^^ +>() => true : () => true +> : ^^^^^^^^^^ >true : true > : ^^^^ @@ -32,8 +32,8 @@ export const inlined: { (): boolean; nun: 456 } = () => true; > : ^^^^^^ ^^^^^^^ ^^^ >nun : 456 > : ^^^ ->() => true : { (): true; nun: 456; } -> : ^^^^^^^^^^^^^^^^^^^^^^^ +>() => true : () => true +> : ^^^^^^^^^^ >true : true > : ^^^^ @@ -50,10 +50,10 @@ inlined.nun = 456; > : ^^^ export const ignoreJsdoc = () => true; ->ignoreJsdoc : { (): boolean; extra: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->() => true : { (): boolean; extra: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>ignoreJsdoc : () => boolean +> : ^^^^^^^^^^^^^ +>() => true : () => boolean +> : ^^^^^^^^^^^^^ >true : true > : ^^^^ @@ -61,12 +61,12 @@ export const ignoreJsdoc = () => true; ignoreJsdoc.extra = 111 >ignoreJsdoc.extra = 111 : 111 > : ^^^ ->ignoreJsdoc.extra : number -> : ^^^^^^ ->ignoreJsdoc : { (): boolean; extra: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->extra : number -> : ^^^^^^ +>ignoreJsdoc.extra : any +> : ^^^ +>ignoreJsdoc : () => boolean +> : ^^^^^^^^^^^^^ +>extra : any +> : ^^^ >111 : 111 > : ^^^ diff --git a/tests/baselines/reference/referencesForStringLiteralPropertyNames6.baseline.jsonc b/tests/baselines/reference/referencesForStringLiteralPropertyNames6.baseline.jsonc index 24bdcce28d780..2e77e5dd023e6 100644 --- a/tests/baselines/reference/referencesForStringLiteralPropertyNames6.baseline.jsonc +++ b/tests/baselines/reference/referencesForStringLiteralPropertyNames6.baseline.jsonc @@ -1,128 +1,34 @@ // === findAllReferences === // === /tests/cases/fourslash/referencesForStringLiteralPropertyNames6.ts === // const x = function () { return 111111; } -// x./*FIND ALL REFS*/[|{| isWriteAccess: true, isDefinition: true |}someProperty|] = 5; -// x["[|{| isWriteAccess: true, isDefinition: true |}someProperty|]"] = 3; - - // === Definitions === - // === /tests/cases/fourslash/referencesForStringLiteralPropertyNames6.ts === - // const x = function () { return 111111; } - // <|x./*FIND ALL REFS*/[|someProperty|]|> = 5; - // x["someProperty"] = 3; - - // === Details === - [ - { - "containerKind": "", - "containerName": "", - "kind": "property", - "name": "(property) x.someProperty: number", - "displayParts": [ - { - "text": "(", - "kind": "punctuation" - }, - { - "text": "property", - "kind": "text" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "x", - "kind": "localName" - }, - { - "text": ".", - "kind": "punctuation" - }, - { - "text": "someProperty", - "kind": "propertyName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "number", - "kind": "keyword" - } - ] - } - ] +// x./*FIND ALL REFS*/someProperty = 5; +// x["someProperty"] = 3; // === findAllReferences === // === /tests/cases/fourslash/referencesForStringLiteralPropertyNames6.ts === // const x = function () { return 111111; } -// x.[|{| isWriteAccess: true, isDefinition: true |}someProperty|] = 5; -// x["/*FIND ALL REFS*/[|{| isWriteAccess: true, isDefinition: true |}someProperty|]"] = 3; +// x.someProperty = 5; +// x["/*FIND ALL REFS*/[|{| isWriteAccess: true, isInString: true |}someProperty|]"] = 3; // === Definitions === // === /tests/cases/fourslash/referencesForStringLiteralPropertyNames6.ts === // const x = function () { return 111111; } - // <|x.[|someProperty|]|> = 5; - // x["/*FIND ALL REFS*/someProperty"] = 3; + // x.someProperty = 5; + // x["/*FIND ALL REFS*/[|someProperty|]"] = 3; // === Details === [ { "containerKind": "", "containerName": "", - "kind": "property", - "name": "(property) x.someProperty: number", + "kind": "var", + "name": "someProperty", "displayParts": [ { - "text": "(", - "kind": "punctuation" - }, - { - "text": "property", - "kind": "text" - }, - { - "text": ")", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "x", - "kind": "localName" - }, - { - "text": ".", - "kind": "punctuation" - }, - { - "text": "someProperty", - "kind": "propertyName" - }, - { - "text": ":", - "kind": "punctuation" - }, - { - "text": " ", - "kind": "space" - }, - { - "text": "number", - "kind": "keyword" + "text": "\"someProperty\"", + "kind": "stringLiteral" } ] } diff --git a/tests/baselines/reference/topLevelBlockExpando.errors.txt b/tests/baselines/reference/topLevelBlockExpando.errors.txt new file mode 100644 index 0000000000000..aac12129a555d --- /dev/null +++ b/tests/baselines/reference/topLevelBlockExpando.errors.txt @@ -0,0 +1,53 @@ +check.ts(9,8): error TS2339: Property 'first' does not exist on type '() => number'. +check.ts(10,8): error TS2339: Property 'last' does not exist on type '() => number'. +check.ts(11,9): error TS2322: Type '() => number' is not assignable to type 'Person'. + + +==== check.ts (3 errors) ==== + // https://github.com/microsoft/TypeScript/issues/31972 + interface Person { + first: string; + last: string; + } + + { + const dice = () => Math.floor(Math.random() * 6); + dice.first = 'Rando'; + ~~~~~ +!!! error TS2339: Property 'first' does not exist on type '() => number'. + dice.last = 'Calrissian'; + ~~~~ +!!! error TS2339: Property 'last' does not exist on type '() => number'. + const diceP: Person = dice; + ~~~~~ +!!! error TS2322: Type '() => number' is not assignable to type 'Person'. + } + +==== check.js (0 errors) ==== + // Creates a type { first:string, last: string } + /** + * @typedef {Object} Human - creates a new type named 'SpecialType' + * @property {string} first - a string property of SpecialType + * @property {string} last - a number property of SpecialType + */ + + /** + * @param {Human} param used as a validation tool + */ + function doHumanThings(param) {} + + const dice1 = () => Math.floor(Math.random() * 6); + // dice1.first = 'Rando'; + dice1.last = 'Calrissian'; + + // doHumanThings(dice) + + // but inside a block... you can't call a human + { + const dice2 = () => Math.floor(Math.random() * 6); + dice2.first = 'Rando'; + dice2.last = 'Calrissian'; + + doHumanThings(dice2) + } + \ No newline at end of file diff --git a/tests/baselines/reference/topLevelBlockExpando.symbols b/tests/baselines/reference/topLevelBlockExpando.symbols index e18e54771bc2c..b6f9c9a5b6bfb 100644 --- a/tests/baselines/reference/topLevelBlockExpando.symbols +++ b/tests/baselines/reference/topLevelBlockExpando.symbols @@ -23,14 +23,10 @@ interface Person { >random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) dice.first = 'Rando'; ->dice.first : Symbol(dice.first, Decl(check.ts, 7, 51)) >dice : Symbol(dice, Decl(check.ts, 7, 7)) ->first : Symbol(dice.first, Decl(check.ts, 7, 51)) dice.last = 'Calrissian'; ->dice.last : Symbol(dice.last, Decl(check.ts, 8, 23)) >dice : Symbol(dice, Decl(check.ts, 7, 7)) ->last : Symbol(dice.last, Decl(check.ts, 8, 23)) const diceP: Person = dice; >diceP : Symbol(diceP, Decl(check.ts, 10, 7)) diff --git a/tests/baselines/reference/topLevelBlockExpando.types b/tests/baselines/reference/topLevelBlockExpando.types index ce3b89ad79a89..7d22a38580508 100644 --- a/tests/baselines/reference/topLevelBlockExpando.types +++ b/tests/baselines/reference/topLevelBlockExpando.types @@ -14,10 +14,10 @@ interface Person { { const dice = () => Math.floor(Math.random() * 6); ->dice : { (): number; first: string; last: string; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->() => Math.floor(Math.random() * 6) : { (): number; first: string; last: string; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>dice : () => number +> : ^^^^^^^^^^^^ +>() => Math.floor(Math.random() * 6) : () => number +> : ^^^^^^^^^^^^ >Math.floor(Math.random() * 6) : number > : ^^^^^^ >Math.floor : (x: number) => number @@ -42,32 +42,32 @@ interface Person { dice.first = 'Rando'; >dice.first = 'Rando' : "Rando" > : ^^^^^^^ ->dice.first : string -> : ^^^^^^ ->dice : { (): number; first: string; last: string; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->first : string -> : ^^^^^^ +>dice.first : any +> : ^^^ +>dice : () => number +> : ^^^^^^^^^^^^ +>first : any +> : ^^^ >'Rando' : "Rando" > : ^^^^^^^ dice.last = 'Calrissian'; >dice.last = 'Calrissian' : "Calrissian" > : ^^^^^^^^^^^^ ->dice.last : string -> : ^^^^^^ ->dice : { (): number; first: string; last: string; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->last : string -> : ^^^^^^ +>dice.last : any +> : ^^^ +>dice : () => number +> : ^^^^^^^^^^^^ +>last : any +> : ^^^ >'Calrissian' : "Calrissian" > : ^^^^^^^^^^^^ const diceP: Person = dice; >diceP : Person > : ^^^^^^ ->dice : { (): number; first: string; last: string; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>dice : () => number +> : ^^^^^^^^^^^^ } === check.js === diff --git a/tests/baselines/reference/typeFromPropertyAssignment29.errors.txt b/tests/baselines/reference/typeFromPropertyAssignment29.errors.txt index e0e11b7327889..c1bd5fec72537 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment29.errors.txt +++ b/tests/baselines/reference/typeFromPropertyAssignment29.errors.txt @@ -1,3 +1,11 @@ +typeFromPropertyAssignment29.ts(13,13): error TS2339: Property 'prop' does not exist on type '(n: number) => string'. +typeFromPropertyAssignment29.ts(14,13): error TS2339: Property 'prop' does not exist on type '(n: number) => string'. +typeFromPropertyAssignment29.ts(15,13): error TS2339: Property 'm' does not exist on type '(n: number) => string'. +typeFromPropertyAssignment29.ts(18,22): error TS2339: Property 'prop' does not exist on type '(n: number) => string'. +typeFromPropertyAssignment29.ts(18,49): error TS2339: Property 'm' does not exist on type '(n: number) => string'. +typeFromPropertyAssignment29.ts(21,14): error TS2339: Property 'prop' does not exist on type '(n: number) => string'. +typeFromPropertyAssignment29.ts(22,14): error TS2339: Property 'm' does not exist on type '(n: number) => string'. +typeFromPropertyAssignment29.ts(31,12): error TS2339: Property 'total' does not exist on type '(m: number) => number'. typeFromPropertyAssignment29.ts(60,14): error TS2339: Property 'prop' does not exist on type '(n: number) => string'. typeFromPropertyAssignment29.ts(61,14): error TS2339: Property 'm' does not exist on type '(n: number) => string'. typeFromPropertyAssignment29.ts(64,22): error TS2339: Property 'prop' does not exist on type '(n: number) => string'. @@ -12,7 +20,7 @@ typeFromPropertyAssignment29.ts(84,22): error TS2339: Property 'prop' does not e typeFromPropertyAssignment29.ts(84,42): error TS2339: Property 'm' does not exist on type 'typeof ExpandoExpr3'. -==== typeFromPropertyAssignment29.ts (12 errors) ==== +==== typeFromPropertyAssignment29.ts (20 errors) ==== function ExpandoDecl(n: number) { return n.toString(); } @@ -26,15 +34,29 @@ typeFromPropertyAssignment29.ts(84,42): error TS2339: Property 'm' does not exis return n.toString(); } ExpandoExpr.prop = { x: 2 } + ~~~~ +!!! error TS2339: Property 'prop' does not exist on type '(n: number) => string'. ExpandoExpr.prop = { y: "" } + ~~~~ +!!! error TS2339: Property 'prop' does not exist on type '(n: number) => string'. ExpandoExpr.m = function(n: number) { + ~ +!!! error TS2339: Property 'm' does not exist on type '(n: number) => string'. return n + 1; } var n = (ExpandoExpr.prop.x || 0) + ExpandoExpr.m(12) + ExpandoExpr(101).length + ~~~~ +!!! error TS2339: Property 'prop' does not exist on type '(n: number) => string'. + ~ +!!! error TS2339: Property 'm' does not exist on type '(n: number) => string'. const ExpandoArrow = (n: number) => n.toString(); ExpandoArrow.prop = 2 + ~~~~ +!!! error TS2339: Property 'prop' does not exist on type '(n: number) => string'. ExpandoArrow.m = function(n: number) { + ~ +!!! error TS2339: Property 'm' does not exist on type '(n: number) => string'. return n + 1; } @@ -44,6 +66,8 @@ typeFromPropertyAssignment29.ts(84,42): error TS2339: Property 'm' does not exis return n + m; }; nested.total = n + 1_000_000; + ~~~~~ +!!! error TS2339: Property 'total' does not exist on type '(m: number) => number'. return nested; } ExpandoNested.also = -1; diff --git a/tests/baselines/reference/typeFromPropertyAssignment29.js b/tests/baselines/reference/typeFromPropertyAssignment29.js index bb80757f59303..df6a5537e3f82 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment29.js +++ b/tests/baselines/reference/typeFromPropertyAssignment29.js @@ -181,27 +181,10 @@ declare namespace ExpandoDecl { var m: (n: number) => number; } declare var n: number; -declare const ExpandoExpr: { - (n: number): string; - prop: { - x: number; - y?: undefined; - } | { - y: string; - x?: undefined; - }; - m(n: number): number; -}; +declare const ExpandoExpr: (n: number) => string; declare var n: number; -declare const ExpandoArrow: { - (n: number): string; - prop: number; - m(n: number): number; -}; -declare function ExpandoNested(n: number): { - (m: number): number; - total: number; -}; +declare const ExpandoArrow: (n: number) => string; +declare function ExpandoNested(n: number): (m: number) => number; declare namespace ExpandoNested { var also: number; } diff --git a/tests/baselines/reference/typeFromPropertyAssignment29.symbols b/tests/baselines/reference/typeFromPropertyAssignment29.symbols index 71f5be0c2a073..525136a8c9ada 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment29.symbols +++ b/tests/baselines/reference/typeFromPropertyAssignment29.symbols @@ -46,21 +46,15 @@ const ExpandoExpr = function (n: number) { >toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) } ExpandoExpr.prop = { x: 2 } ->ExpandoExpr.prop : Symbol(ExpandoExpr.prop, Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27)) >ExpandoExpr : Symbol(ExpandoExpr, Decl(typeFromPropertyAssignment29.ts, 9, 5), Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27), Decl(typeFromPropertyAssignment29.ts, 13, 28)) ->prop : Symbol(ExpandoExpr.prop, Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27)) >x : Symbol(x, Decl(typeFromPropertyAssignment29.ts, 12, 20)) ExpandoExpr.prop = { y: "" } ->ExpandoExpr.prop : Symbol(ExpandoExpr.prop, Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27)) >ExpandoExpr : Symbol(ExpandoExpr, Decl(typeFromPropertyAssignment29.ts, 9, 5), Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27), Decl(typeFromPropertyAssignment29.ts, 13, 28)) ->prop : Symbol(ExpandoExpr.prop, Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27)) >y : Symbol(y, Decl(typeFromPropertyAssignment29.ts, 13, 20)) ExpandoExpr.m = function(n: number) { ->ExpandoExpr.m : Symbol(ExpandoExpr.m, Decl(typeFromPropertyAssignment29.ts, 13, 28)) >ExpandoExpr : Symbol(ExpandoExpr, Decl(typeFromPropertyAssignment29.ts, 9, 5), Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27), Decl(typeFromPropertyAssignment29.ts, 13, 28)) ->m : Symbol(ExpandoExpr.m, Decl(typeFromPropertyAssignment29.ts, 13, 28)) >n : Symbol(n, Decl(typeFromPropertyAssignment29.ts, 14, 25)) return n + 1; @@ -68,14 +62,8 @@ ExpandoExpr.m = function(n: number) { } var n = (ExpandoExpr.prop.x || 0) + ExpandoExpr.m(12) + ExpandoExpr(101).length >n : Symbol(n, Decl(typeFromPropertyAssignment29.ts, 7, 3), Decl(typeFromPropertyAssignment29.ts, 17, 3), Decl(typeFromPropertyAssignment29.ts, 45, 3), Decl(typeFromPropertyAssignment29.ts, 63, 3), Decl(typeFromPropertyAssignment29.ts, 73, 3) ... and 1 more) ->ExpandoExpr.prop.x : Symbol(x, Decl(typeFromPropertyAssignment29.ts, 12, 20)) ->ExpandoExpr.prop : Symbol(ExpandoExpr.prop, Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27)) >ExpandoExpr : Symbol(ExpandoExpr, Decl(typeFromPropertyAssignment29.ts, 9, 5), Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27), Decl(typeFromPropertyAssignment29.ts, 13, 28)) ->prop : Symbol(ExpandoExpr.prop, Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27)) ->x : Symbol(x, Decl(typeFromPropertyAssignment29.ts, 12, 20)) ->ExpandoExpr.m : Symbol(ExpandoExpr.m, Decl(typeFromPropertyAssignment29.ts, 13, 28)) >ExpandoExpr : Symbol(ExpandoExpr, Decl(typeFromPropertyAssignment29.ts, 9, 5), Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27), Decl(typeFromPropertyAssignment29.ts, 13, 28)) ->m : Symbol(ExpandoExpr.m, Decl(typeFromPropertyAssignment29.ts, 13, 28)) >ExpandoExpr(101).length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) >ExpandoExpr : Symbol(ExpandoExpr, Decl(typeFromPropertyAssignment29.ts, 9, 5), Decl(typeFromPropertyAssignment29.ts, 11, 1), Decl(typeFromPropertyAssignment29.ts, 12, 27), Decl(typeFromPropertyAssignment29.ts, 13, 28)) >length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) @@ -88,14 +76,10 @@ const ExpandoArrow = (n: number) => n.toString(); >toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) ExpandoArrow.prop = 2 ->ExpandoArrow.prop : Symbol(ExpandoArrow.prop, Decl(typeFromPropertyAssignment29.ts, 19, 49)) >ExpandoArrow : Symbol(ExpandoArrow, Decl(typeFromPropertyAssignment29.ts, 19, 5), Decl(typeFromPropertyAssignment29.ts, 19, 49), Decl(typeFromPropertyAssignment29.ts, 20, 21)) ->prop : Symbol(ExpandoArrow.prop, Decl(typeFromPropertyAssignment29.ts, 19, 49)) ExpandoArrow.m = function(n: number) { ->ExpandoArrow.m : Symbol(ExpandoArrow.m, Decl(typeFromPropertyAssignment29.ts, 20, 21)) >ExpandoArrow : Symbol(ExpandoArrow, Decl(typeFromPropertyAssignment29.ts, 19, 5), Decl(typeFromPropertyAssignment29.ts, 19, 49), Decl(typeFromPropertyAssignment29.ts, 20, 21)) ->m : Symbol(ExpandoArrow.m, Decl(typeFromPropertyAssignment29.ts, 20, 21)) >n : Symbol(n, Decl(typeFromPropertyAssignment29.ts, 21, 26)) return n + 1; @@ -117,9 +101,7 @@ function ExpandoNested(n: number) { }; nested.total = n + 1_000_000; ->nested.total : Symbol(nested.total, Decl(typeFromPropertyAssignment29.ts, 29, 6)) >nested : Symbol(nested, Decl(typeFromPropertyAssignment29.ts, 27, 9)) ->total : Symbol(nested.total, Decl(typeFromPropertyAssignment29.ts, 29, 6)) >n : Symbol(n, Decl(typeFromPropertyAssignment29.ts, 26, 23)) return nested; diff --git a/tests/baselines/reference/typeFromPropertyAssignment29.types b/tests/baselines/reference/typeFromPropertyAssignment29.types index 24b9cb40ac25d..973a5e502064a 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment29.types +++ b/tests/baselines/reference/typeFromPropertyAssignment29.types @@ -86,10 +86,10 @@ var n = ExpandoDecl.prop + ExpandoDecl.m(12) + ExpandoDecl(101).length > : ^^^^^^ const ExpandoExpr = function (n: number) { ->ExpandoExpr : { (n: number): string; prop: { x: number; y?: undefined; } | { y: string; x?: undefined; }; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ ->function (n: number) { return n.toString();} : { (n: number): string; prop: { x: number; y?: undefined; } | { y: string; x?: undefined; }; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ +>ExpandoExpr : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ +>function (n: number) { return n.toString();} : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ >n : number > : ^^^^^^ @@ -106,12 +106,12 @@ const ExpandoExpr = function (n: number) { ExpandoExpr.prop = { x: 2 } >ExpandoExpr.prop = { x: 2 } : { x: number; } > : ^^^^^^^^^^^^^^ ->ExpandoExpr.prop : { x: number; y?: undefined; } | { y: string; x?: undefined; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->ExpandoExpr : { (n: number): string; prop: { x: number; y?: undefined; } | { y: string; x?: undefined; }; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ ->prop : { x: number; y?: undefined; } | { y: string; x?: undefined; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>ExpandoExpr.prop : any +> : ^^^ +>ExpandoExpr : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ +>prop : any +> : ^^^ >{ x: 2 } : { x: number; } > : ^^^^^^^^^^^^^^ >x : number @@ -122,12 +122,12 @@ ExpandoExpr.prop = { x: 2 } ExpandoExpr.prop = { y: "" } >ExpandoExpr.prop = { y: "" } : { y: string; } > : ^^^^^^^^^^^^^^ ->ExpandoExpr.prop : { x: number; y?: undefined; } | { y: string; x?: undefined; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->ExpandoExpr : { (n: number): string; prop: { x: number; y?: undefined; } | { y: string; x?: undefined; }; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ ->prop : { x: number; y?: undefined; } | { y: string; x?: undefined; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>ExpandoExpr.prop : any +> : ^^^ +>ExpandoExpr : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ +>prop : any +> : ^^^ >{ y: "" } : { y: string; } > : ^^^^^^^^^^^^^^ >y : string @@ -138,12 +138,12 @@ ExpandoExpr.prop = { y: "" } ExpandoExpr.m = function(n: number) { >ExpandoExpr.m = function(n: number) { return n + 1;} : (n: number) => number > : ^ ^^ ^^^^^^^^^^^ ->ExpandoExpr.m : (n: number) => number -> : ^ ^^ ^^^^^^^^^^^ ->ExpandoExpr : { (n: number): string; prop: { x: number; y?: undefined; } | { y: string; x?: undefined; }; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ ->m : (n: number) => number -> : ^ ^^ ^^^^^^^^^^^ +>ExpandoExpr.m : any +> : ^^^ +>ExpandoExpr : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ +>m : any +> : ^^^ >function(n: number) { return n + 1;} : (n: number) => number > : ^ ^^ ^^^^^^^^^^^ >n : number @@ -160,52 +160,52 @@ ExpandoExpr.m = function(n: number) { var n = (ExpandoExpr.prop.x || 0) + ExpandoExpr.m(12) + ExpandoExpr(101).length >n : number > : ^^^^^^ ->(ExpandoExpr.prop.x || 0) + ExpandoExpr.m(12) + ExpandoExpr(101).length : number -> : ^^^^^^ ->(ExpandoExpr.prop.x || 0) + ExpandoExpr.m(12) : number -> : ^^^^^^ ->(ExpandoExpr.prop.x || 0) : 0 -> : ^ ->ExpandoExpr.prop.x || 0 : 0 -> : ^ ->ExpandoExpr.prop.x : undefined -> : ^^^^^^^^^ ->ExpandoExpr.prop : { y: string; x?: undefined; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->ExpandoExpr : { (n: number): string; prop: { x: number; y?: undefined; } | { y: string; x?: undefined; }; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ ->prop : { y: string; x?: undefined; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->x : undefined -> : ^^^^^^^^^ +>(ExpandoExpr.prop.x || 0) + ExpandoExpr.m(12) + ExpandoExpr(101).length : any +> : ^^^ +>(ExpandoExpr.prop.x || 0) + ExpandoExpr.m(12) : any +> : ^^^ +>(ExpandoExpr.prop.x || 0) : any +> : ^^^ +>ExpandoExpr.prop.x || 0 : any +> : ^^^ +>ExpandoExpr.prop.x : any +> : ^^^ +>ExpandoExpr.prop : any +> : ^^^ +>ExpandoExpr : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ +>prop : any +> : ^^^ +>x : any +> : ^^^ >0 : 0 > : ^ ->ExpandoExpr.m(12) : number -> : ^^^^^^ ->ExpandoExpr.m : (n: number) => number -> : ^ ^^ ^^^^^^^^^^^ ->ExpandoExpr : { (n: number): string; prop: { x: number; y?: undefined; } | { y: string; x?: undefined; }; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ ->m : (n: number) => number -> : ^ ^^ ^^^^^^^^^^^ +>ExpandoExpr.m(12) : any +> : ^^^ +>ExpandoExpr.m : any +> : ^^^ +>ExpandoExpr : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ +>m : any +> : ^^^ >12 : 12 > : ^^ >ExpandoExpr(101).length : number > : ^^^^^^ >ExpandoExpr(101) : string > : ^^^^^^ ->ExpandoExpr : { (n: number): string; prop: { x: number; y?: undefined; } | { y: string; x?: undefined; }; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ +>ExpandoExpr : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ >101 : 101 > : ^^^ >length : number > : ^^^^^^ const ExpandoArrow = (n: number) => n.toString(); ->ExpandoArrow : { (n: number): string; prop: number; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ ->(n: number) => n.toString() : { (n: number): string; prop: number; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ +>ExpandoArrow : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ +>(n: number) => n.toString() : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ >n : number > : ^^^^^^ >n.toString() : string @@ -220,24 +220,24 @@ const ExpandoArrow = (n: number) => n.toString(); ExpandoArrow.prop = 2 >ExpandoArrow.prop = 2 : 2 > : ^ ->ExpandoArrow.prop : number -> : ^^^^^^ ->ExpandoArrow : { (n: number): string; prop: number; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ ->prop : number -> : ^^^^^^ +>ExpandoArrow.prop : any +> : ^^^ +>ExpandoArrow : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ +>prop : any +> : ^^^ >2 : 2 > : ^ ExpandoArrow.m = function(n: number) { >ExpandoArrow.m = function(n: number) { return n + 1;} : (n: number) => number > : ^ ^^ ^^^^^^^^^^^ ->ExpandoArrow.m : (n: number) => number -> : ^ ^^ ^^^^^^^^^^^ ->ExpandoArrow : { (n: number): string; prop: number; m(n: number): number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ ->m : (n: number) => number -> : ^ ^^ ^^^^^^^^^^^ +>ExpandoArrow.m : any +> : ^^^ +>ExpandoArrow : (n: number) => string +> : ^ ^^ ^^^^^^^^^^^ +>m : any +> : ^^^ >function(n: number) { return n + 1;} : (n: number) => number > : ^ ^^ ^^^^^^^^^^^ >n : number @@ -260,10 +260,10 @@ function ExpandoNested(n: number) { > : ^^^^^^ const nested = function (m: number) { ->nested : { (m: number): number; total: number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->function (m: number) { return n + m; } : { (m: number): number; total: number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>nested : (m: number) => number +> : ^ ^^ ^^^^^^^^^^^ +>function (m: number) { return n + m; } : (m: number) => number +> : ^ ^^ ^^^^^^^^^^^ >m : number > : ^^^^^^ @@ -279,12 +279,12 @@ function ExpandoNested(n: number) { nested.total = n + 1_000_000; >nested.total = n + 1_000_000 : number > : ^^^^^^ ->nested.total : number -> : ^^^^^^ ->nested : { (m: number): number; total: number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->total : number -> : ^^^^^^ +>nested.total : any +> : ^^^ +>nested : (m: number) => number +> : ^ ^^ ^^^^^^^^^^^ +>total : any +> : ^^^ >n + 1_000_000 : number > : ^^^^^^ >n : number @@ -293,8 +293,8 @@ function ExpandoNested(n: number) { > : ^^^^^^^ return nested; ->nested : { (m: number): number; total: number; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>nested : (m: number) => number +> : ^ ^^ ^^^^^^^^^^^ } ExpandoNested.also = -1; >ExpandoNested.also = -1 : -1 diff --git a/tests/baselines/reference/typeFromPropertyAssignment30.types b/tests/baselines/reference/typeFromPropertyAssignment30.types index 4959800e3d23a..ea33bfeae3f5b 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment30.types +++ b/tests/baselines/reference/typeFromPropertyAssignment30.types @@ -12,8 +12,8 @@ interface Combo { const c: Combo = () => 1 >c : Combo > : ^^^^^ ->() => 1 : { (): number; p: {}; } -> : ^^^^^^^^^^^^^^^^^^^^^^ +>() => 1 : () => number +> : ^^^^^^^^^^^^ >1 : 1 > : ^ diff --git a/tests/baselines/reference/typeFromPropertyAssignment36.errors.txt b/tests/baselines/reference/typeFromPropertyAssignment36.errors.txt index d7e288f590806..933026dafde09 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment36.errors.txt +++ b/tests/baselines/reference/typeFromPropertyAssignment36.errors.txt @@ -1,9 +1,13 @@ typeFromPropertyAssignment36.ts(11,7): error TS2565: Property 'q' is used before being assigned. typeFromPropertyAssignment36.ts(42,3): error TS2565: Property 'q' is used before being assigned. -typeFromPropertyAssignment36.ts(64,3): error TS2565: Property 'expando' is used before being assigned. +typeFromPropertyAssignment36.ts(62,7): error TS2339: Property 'expando' does not exist on type '() => void'. +typeFromPropertyAssignment36.ts(64,3): error TS2339: Property 'expando' does not exist on type '() => void'. +typeFromPropertyAssignment36.ts(67,7): error TS2339: Property 'both' does not exist on type '() => void'. +typeFromPropertyAssignment36.ts(70,7): error TS2339: Property 'both' does not exist on type '() => void'. +typeFromPropertyAssignment36.ts(72,3): error TS2339: Property 'both' does not exist on type '() => void'. -==== typeFromPropertyAssignment36.ts (3 errors) ==== +==== typeFromPropertyAssignment36.ts (7 errors) ==== function f(b: boolean) { function d() { } @@ -70,16 +74,24 @@ typeFromPropertyAssignment36.ts(64,3): error TS2565: Property 'expando' is used } if (!!false) { g.expando = 1 + ~~~~~~~ +!!! error TS2339: Property 'expando' does not exist on type '() => void'. } g.expando // error ~~~~~~~ -!!! error TS2565: Property 'expando' is used before being assigned. +!!! error TS2339: Property 'expando' does not exist on type '() => void'. if (!!false) { g.both = 'hi' + ~~~~ +!!! error TS2339: Property 'both' does not exist on type '() => void'. } else { g.both = 0 + ~~~~ +!!! error TS2339: Property 'both' does not exist on type '() => void'. } g.both + ~~~~ +!!! error TS2339: Property 'both' does not exist on type '() => void'. \ No newline at end of file diff --git a/tests/baselines/reference/typeFromPropertyAssignment36.symbols b/tests/baselines/reference/typeFromPropertyAssignment36.symbols index b297a57442177..06ba327079ab1 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment36.symbols +++ b/tests/baselines/reference/typeFromPropertyAssignment36.symbols @@ -152,29 +152,19 @@ const g = function() { } if (!!false) { g.expando = 1 ->g.expando : Symbol(g.expando, Decl(typeFromPropertyAssignment36.ts, 60, 14)) >g : Symbol(g, Decl(typeFromPropertyAssignment36.ts, 58, 5)) ->expando : Symbol(g.expando, Decl(typeFromPropertyAssignment36.ts, 60, 14)) } g.expando // error ->g.expando : Symbol(g.expando, Decl(typeFromPropertyAssignment36.ts, 60, 14)) >g : Symbol(g, Decl(typeFromPropertyAssignment36.ts, 58, 5)) ->expando : Symbol(g.expando, Decl(typeFromPropertyAssignment36.ts, 60, 14)) if (!!false) { g.both = 'hi' ->g.both : Symbol(g.both, Decl(typeFromPropertyAssignment36.ts, 65, 14), Decl(typeFromPropertyAssignment36.ts, 68, 6)) >g : Symbol(g, Decl(typeFromPropertyAssignment36.ts, 58, 5)) ->both : Symbol(g.both, Decl(typeFromPropertyAssignment36.ts, 65, 14), Decl(typeFromPropertyAssignment36.ts, 68, 6)) } else { g.both = 0 ->g.both : Symbol(g.both, Decl(typeFromPropertyAssignment36.ts, 65, 14), Decl(typeFromPropertyAssignment36.ts, 68, 6)) >g : Symbol(g, Decl(typeFromPropertyAssignment36.ts, 58, 5)) ->both : Symbol(g.both, Decl(typeFromPropertyAssignment36.ts, 65, 14), Decl(typeFromPropertyAssignment36.ts, 68, 6)) } g.both ->g.both : Symbol(g.both, Decl(typeFromPropertyAssignment36.ts, 65, 14), Decl(typeFromPropertyAssignment36.ts, 68, 6)) >g : Symbol(g, Decl(typeFromPropertyAssignment36.ts, 58, 5)) ->both : Symbol(g.both, Decl(typeFromPropertyAssignment36.ts, 65, 14), Decl(typeFromPropertyAssignment36.ts, 68, 6)) diff --git a/tests/baselines/reference/typeFromPropertyAssignment36.types b/tests/baselines/reference/typeFromPropertyAssignment36.types index aa202b609f5b4..417fa0c5e8915 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment36.types +++ b/tests/baselines/reference/typeFromPropertyAssignment36.types @@ -301,10 +301,10 @@ d.r // test function expressions too const g = function() { ->g : { (): void; expando: number; both: string | number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->function() {} : { (): void; expando: number; both: string | number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>g : () => void +> : ^^^^^^^^^^ +>function() {} : () => void +> : ^^^^^^^^^^ } if (!!false) { >!!false : false @@ -317,22 +317,22 @@ if (!!false) { g.expando = 1 >g.expando = 1 : 1 > : ^ ->g.expando : number -> : ^^^^^^ ->g : { (): void; expando: number; both: string | number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->expando : number -> : ^^^^^^ +>g.expando : any +> : ^^^ +>g : () => void +> : ^^^^^^^^^^ +>expando : any +> : ^^^ >1 : 1 > : ^ } g.expando // error ->g.expando : number -> : ^^^^^^ ->g : { (): void; expando: number; both: string | number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->expando : number -> : ^^^^^^ +>g.expando : any +> : ^^^ +>g : () => void +> : ^^^^^^^^^^ +>expando : any +> : ^^^ if (!!false) { >!!false : false @@ -345,12 +345,12 @@ if (!!false) { g.both = 'hi' >g.both = 'hi' : "hi" > : ^^^^ ->g.both : string | number -> : ^^^^^^^^^^^^^^^ ->g : { (): void; expando: number; both: string | number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->both : string | number -> : ^^^^^^^^^^^^^^^ +>g.both : any +> : ^^^ +>g : () => void +> : ^^^^^^^^^^ +>both : any +> : ^^^ >'hi' : "hi" > : ^^^^ } @@ -358,20 +358,20 @@ else { g.both = 0 >g.both = 0 : 0 > : ^ ->g.both : string | number -> : ^^^^^^^^^^^^^^^ ->g : { (): void; expando: number; both: string | number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->both : string | number -> : ^^^^^^^^^^^^^^^ +>g.both : any +> : ^^^ +>g : () => void +> : ^^^^^^^^^^ +>both : any +> : ^^^ >0 : 0 > : ^ } g.both ->g.both : string | number -> : ^^^^^^^^^^^^^^^ ->g : { (): void; expando: number; both: string | number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->both : string | number -> : ^^^^^^^^^^^^^^^ +>g.both : any +> : ^^^ +>g : () => void +> : ^^^^^^^^^^ +>both : any +> : ^^^ diff --git a/tests/baselines/reference/typeFromPropertyAssignment38.errors.txt b/tests/baselines/reference/typeFromPropertyAssignment38.errors.txt new file mode 100644 index 0000000000000..511580b24cf17 --- /dev/null +++ b/tests/baselines/reference/typeFromPropertyAssignment38.errors.txt @@ -0,0 +1,14 @@ +typeFromPropertyAssignment38.ts(5,1): error TS7053: Element implicitly has an 'any' type because expression of type '"prop"' can't be used to index type '() => void'. + Property 'prop' does not exist on type '() => void'. + + +==== typeFromPropertyAssignment38.ts (1 errors) ==== + function F() {} + F["prop"] = 3; + + const f = function () {}; + f["prop"] = 3; + ~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"prop"' can't be used to index type '() => void'. +!!! error TS7053: Property 'prop' does not exist on type '() => void'. + \ No newline at end of file diff --git a/tests/baselines/reference/typeFromPropertyAssignment38.symbols b/tests/baselines/reference/typeFromPropertyAssignment38.symbols index 8e3bd0a804b92..600ed66c92f61 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment38.symbols +++ b/tests/baselines/reference/typeFromPropertyAssignment38.symbols @@ -13,5 +13,4 @@ const f = function () {}; f["prop"] = 3; >f : Symbol(f, Decl(typeFromPropertyAssignment38.ts, 3, 5), Decl(typeFromPropertyAssignment38.ts, 3, 25)) ->"prop" : Symbol(f["prop"], Decl(typeFromPropertyAssignment38.ts, 3, 25)) diff --git a/tests/baselines/reference/typeFromPropertyAssignment38.types b/tests/baselines/reference/typeFromPropertyAssignment38.types index 0466e9279a8af..5572020c7a44c 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment38.types +++ b/tests/baselines/reference/typeFromPropertyAssignment38.types @@ -18,18 +18,18 @@ F["prop"] = 3; > : ^ const f = function () {}; ->f : { (): void; prop: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->function () {} : { (): void; prop: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>f : () => void +> : ^^^^^^^^^^ +>function () {} : () => void +> : ^^^^^^^^^^ f["prop"] = 3; >f["prop"] = 3 : 3 > : ^ ->f["prop"] : number -> : ^^^^^^ ->f : { (): void; prop: number; } -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>f["prop"] : any +> : ^^^ +>f : () => void +> : ^^^^^^^^^^ >"prop" : "prop" > : ^^^^^^ >3 : 3 diff --git a/tests/cases/conformance/salsa/annotatedExpandoFunc.ts b/tests/cases/conformance/salsa/annotatedExpandoFunc.ts new file mode 100644 index 0000000000000..b0370eead3ff9 --- /dev/null +++ b/tests/cases/conformance/salsa/annotatedExpandoFunc.ts @@ -0,0 +1,20 @@ +// @noEmit: true +interface F { + (): 1; + p: 2; +} +// disallowed +const f: F = () => 1; +f.p = 2; +f.extra = 3 +const r1 = f() + f.p +// function expressions are still allowed, by analogy with function declarations +const e = () => 4 +e.q = 5 +const r2 = e() + e.q +// function declarations are still allowed +function g() { + return 6 +} +g.r = 7 +const r3 = g() + g.r