Skip to content

Fix recursive types in @typedef #40861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14398,7 +14398,7 @@ namespace ts {

function getAliasSymbolForTypeNode(node: Node) {
let host = node.parent;
while (isParenthesizedTypeNode(host) || isTypeOperatorNode(host) && host.operator === SyntaxKind.ReadonlyKeyword) {
while (isParenthesizedTypeNode(host) || isJSDocTypeExpression(host) || isTypeOperatorNode(host) && host.operator === SyntaxKind.ReadonlyKeyword) {
host = host.parent;
}
return isTypeAlias(host) ? getSymbolOfNode(host) : undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/** @type {AssertFunc} */
const assert = check => {
>assert : (check: boolean) => asserts check
>assert : AssertFunc
>check => { if (!check) throw new Error();} : (check: boolean) => asserts check
>check : boolean

Expand Down Expand Up @@ -70,7 +70,7 @@ function f1(x) {

assert(typeof x === "string");
>assert(typeof x === "string") : void
>assert : (check: boolean) => asserts check
>assert : AssertFunc
>typeof x === "string" : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = /** @type {FooFun} */(void 0);
>module.exports : (foo: typeof import("tests/cases/compiler/file")) => string
>module : { "\"tests/cases/compiler/something\"": (foo: typeof import("tests/cases/compiler/file")) => string; }
>exports : (foo: typeof import("tests/cases/compiler/file")) => string
>(void 0) : (foo: typeof import("tests/cases/compiler/file")) => string
>(void 0) : FooFun
>void 0 : undefined
>0 : 0

2 changes: 1 addition & 1 deletion tests/baselines/reference/checkJsdocTypeTag4.types
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ var a;

/** @type {B<number>} */
var b;
>b : { b: number; }
>b : B<number>

48 changes: 24 additions & 24 deletions tests/baselines/reference/contextualTypedSpecialAssignment.types
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ var ns = {}
/** @type {DoneStatus} */
ns.x = {
>ns.x = { status: 'done', m(n) { }} : { status: "done"; m(n: number): void; }
>ns.x : { status: "done"; m(n: number): void; }
>ns.x : DoneStatus
>ns : typeof ns
>x : { status: "done"; m(n: number): void; }
>x : DoneStatus
>{ status: 'done', m(n) { }} : { status: "done"; m(n: number): void; }

status: 'done',
Expand All @@ -28,9 +28,9 @@ ns.x = {

ns.x = {
>ns.x = { status: 'done', m(n) { }} : { status: "done"; m(n: number): void; }
>ns.x : { status: "done"; m(n: number): void; }
>ns.x : DoneStatus
>ns : typeof ns
>x : { status: "done"; m(n: number): void; }
>x : DoneStatus
>{ status: 'done', m(n) { }} : { status: "done"; m(n: number): void; }

status: 'done',
Expand All @@ -42,9 +42,9 @@ ns.x = {
>n : number
}
ns.x
>ns.x : { status: "done"; m(n: number): void; }
>ns.x : DoneStatus
>ns : typeof ns
>x : { status: "done"; m(n: number): void; }
>x : DoneStatus


// this-property assignment
Expand All @@ -55,9 +55,9 @@ class Thing {
/** @type {DoneStatus} */
this.s = {
>this.s = { status: 'done', m(n) { } } : { status: "done"; m(n: number): void; }
>this.s : { status: "done"; m(n: number): void; }
>this.s : DoneStatus
>this : this
>s : { status: "done"; m(n: number): void; }
>s : DoneStatus
>{ status: 'done', m(n) { } } : { status: "done"; m(n: number): void; }

status: 'done',
Expand All @@ -75,9 +75,9 @@ class Thing {

this.s = {
>this.s = { status: 'done', m(n) { } } : { status: "done"; m(n: number): void; }
>this.s : { status: "done"; m(n: number): void; }
>this.s : DoneStatus
>this : this
>s : { status: "done"; m(n: number): void; }
>s : DoneStatus
>{ status: 'done', m(n) { } } : { status: "done"; m(n: number): void; }

status: 'done',
Expand All @@ -96,9 +96,9 @@ class Thing {
/** @type {DoneStatus} */
exports.x = {
>exports.x = { status: "done", m(n) { }} : { status: "done"; m(n: number): void; }
>exports.x : { status: "done"; m(n: number): void; }
>exports.x : DoneStatus
>exports : typeof import("tests/cases/conformance/salsa/test")
>x : { status: "done"; m(n: number): void; }
>x : DoneStatus
>{ status: "done", m(n) { }} : { status: "done"; m(n: number): void; }

status: "done",
Expand All @@ -110,18 +110,18 @@ exports.x = {
>n : number
}
exports.x
>exports.x : { status: "done"; m(n: number): void; }
>exports.x : DoneStatus
>exports : typeof import("tests/cases/conformance/salsa/test")
>x : { status: "done"; m(n: number): void; }
>x : DoneStatus

/** @type {DoneStatus} */
module.exports.y = {
>module.exports.y = { status: "done", m(n) { }} : { status: "done"; m(n: number): void; }
>module.exports.y : { status: "done"; m(n: number): void; }
>module.exports.y : DoneStatus
>module.exports : typeof import("tests/cases/conformance/salsa/test")
>module : { "\"tests/cases/conformance/salsa/test\"": typeof import("tests/cases/conformance/salsa/test"); }
>exports : typeof import("tests/cases/conformance/salsa/test")
>y : { status: "done"; m(n: number): void; }
>y : DoneStatus
>{ status: "done", m(n) { }} : { status: "done"; m(n: number): void; }

status: "done",
Expand All @@ -133,21 +133,21 @@ module.exports.y = {
>n : number
}
module.exports.y
>module.exports.y : { status: "done"; m(n: number): void; }
>module.exports.y : DoneStatus
>module.exports : typeof import("tests/cases/conformance/salsa/test")
>module : { "\"tests/cases/conformance/salsa/test\"": typeof import("tests/cases/conformance/salsa/test"); }
>exports : typeof import("tests/cases/conformance/salsa/test")
>y : { status: "done"; m(n: number): void; }
>y : DoneStatus

// prototype-property assignment
/** @type {DoneStatus} */
Thing.prototype.x = {
>Thing.prototype.x = { status: 'done', m(n) { }} : { status: "done"; m(n: number): void; }
>Thing.prototype.x : { status: "done"; m(n: number): void; }
>Thing.prototype.x : DoneStatus
>Thing.prototype : Thing
>Thing : typeof Thing
>prototype : Thing
>x : { status: "done"; m(n: number): void; }
>x : DoneStatus
>{ status: 'done', m(n) { }} : { status: "done"; m(n: number): void; }

status: 'done',
Expand All @@ -159,11 +159,11 @@ Thing.prototype.x = {
>n : number
}
Thing.prototype.x
>Thing.prototype.x : { status: "done"; m(n: number): void; }
>Thing.prototype.x : DoneStatus
>Thing.prototype : Thing
>Thing : typeof Thing
>prototype : Thing
>x : { status: "done"; m(n: number): void; }
>x : DoneStatus

// prototype assignment
function F() {
Expand All @@ -172,9 +172,9 @@ function F() {
/** @type {DoneStatus} */
F.prototype = {
>F.prototype = { status: "done", m(n) { }} : { status: "done"; m(n: number): void; }
>F.prototype : { status: "done"; m(n: number): void; }
>F.prototype : DoneStatus
>F : typeof F
>prototype : { status: "done"; m(n: number): void; }
>prototype : DoneStatus
>{ status: "done", m(n) { }} : { status: "done"; m(n: number): void; }

status: "done",
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/enumTag.types
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function consume(t,s,f) {
>consume : (t: Target, s: Second, f: Fs) => void
>t : string
>s : number
>f : (arg0: number) => number
>f : Fs

/** @type {string} */
var str = t
Expand All @@ -94,7 +94,7 @@ function consume(t,s,f) {
/** @type {(n: number) => number} */
var fun = f
>fun : (n: number) => number
>f : (arg0: number) => number
>f : Fs

/** @type {Target} */
var v = Target.START
Expand Down
50 changes: 25 additions & 25 deletions tests/baselines/reference/expandoFunctionContextualTypesJs.types
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
* @type {StatelessComponent<MyComponentProps>}
*/
const MyComponent = () => /* @type {any} */(null);
>MyComponent : { (): any; defaultProps?: Partial<{ color: "red" | "blue"; }>; }
>() => /* @type {any} */(null) : { (): any; defaultProps: Partial<{ color: "red" | "blue"; }>; }
>MyComponent : StatelessComponent<MyComponentProps>
>() => /* @type {any} */(null) : { (): any; defaultProps: Partial<MyComponentProps>; }
>(null) : null
>null : null

MyComponent.defaultProps = {
>MyComponent.defaultProps = { color: "red"} : { color: "red"; }
>MyComponent.defaultProps : Partial<{ color: "red" | "blue"; }>
>MyComponent : { (): any; defaultProps?: Partial<{ color: "red" | "blue"; }>; }
>defaultProps : Partial<{ color: "red" | "blue"; }>
>MyComponent.defaultProps : Partial<MyComponentProps>
>MyComponent : StatelessComponent<MyComponentProps>
>defaultProps : Partial<MyComponentProps>
>{ color: "red"} : { color: "red"; }

color: "red"
Expand All @@ -28,18 +28,18 @@ MyComponent.defaultProps = {
};

const MyComponent2 = () => null;
>MyComponent2 : { (): any; defaultProps: { color: "red" | "blue"; }; }
>() => null : { (): any; defaultProps: { color: "red" | "blue"; }; }
>MyComponent2 : { (): any; defaultProps: MyComponentProps; }
>() => null : { (): any; defaultProps: MyComponentProps; }
>null : null

/**
* @type {MyComponentProps}
*/
MyComponent2.defaultProps = {
>MyComponent2.defaultProps = { color: "red"} : { color: "red"; }
>MyComponent2.defaultProps : { color: "red" | "blue"; }
>MyComponent2.defaultProps : MyComponentProps
>MyComponent2 : { (): any; defaultProps: MyComponentProps; }
>defaultProps : { color: "red" | "blue"; }
>defaultProps : MyComponentProps
>{ color: "red"} : { color: "red"; }

color: "red"
Expand All @@ -51,16 +51,16 @@ MyComponent2.defaultProps = {
* @type {StatelessComponent<MyComponentProps>}
*/
const check = MyComponent2;
>check : { (): any; defaultProps?: Partial<{ color: "red" | "blue"; }>; }
>MyComponent2 : { (): any; defaultProps: { color: "red" | "blue"; }; }
>check : StatelessComponent<MyComponentProps>
>MyComponent2 : { (): any; defaultProps: MyComponentProps; }

/**
*
* @param {{ props: MyComponentProps }} p
*/
function expectLiteral(p) {}
>expectLiteral : (p: { props: MyComponentProps;}) => void
>p : { props: { color: "red" | "blue"; }; }
>p : { props: MyComponentProps; }

function foo() {
>foo : typeof foo
Expand All @@ -70,27 +70,27 @@ function foo() {
*/
this.props = { color: "red" };
>this.props = { color: "red" } : { color: "red"; }
>this.props : { color: "red" | "blue"; }
>this.props : MyComponentProps
>this : this
>props : { color: "red" | "blue"; }
>props : MyComponentProps
>{ color: "red" } : { color: "red"; }
>color : "red"
>"red" : "red"

expectLiteral(this);
>expectLiteral(this) : void
>expectLiteral : (p: { props: { color: "red" | "blue"; }; }) => void
>expectLiteral : (p: { props: MyComponentProps; }) => void
>this : this
}

/**
* @type {MyComponentProps}
*/
module.exports = {
>module.exports = { color: "red"} : { color: "red" | "blue"; }
>module.exports : { color: "red" | "blue"; }
>module : { "\"tests/cases/compiler/input\"": { color: "red" | "blue"; }; }
>exports : { color: "red" | "blue"; }
>module.exports = { color: "red"} : MyComponentProps
>module.exports : MyComponentProps
>module : { "\"tests/cases/compiler/input\"": MyComponentProps; }
>exports : MyComponentProps
>{ color: "red"} : { color: "red"; }

color: "red"
Expand All @@ -100,10 +100,10 @@ module.exports = {

expectLiteral({ props: module.exports });
>expectLiteral({ props: module.exports }) : void
>expectLiteral : (p: { props: { color: "red" | "blue"; }; }) => void
>{ props: module.exports } : { props: { color: "red" | "blue"; }; }
>props : { color: "red" | "blue"; }
>module.exports : { color: "red" | "blue"; }
>module : { "\"tests/cases/compiler/input\"": { color: "red" | "blue"; }; }
>exports : { color: "red" | "blue"; }
>expectLiteral : (p: { props: MyComponentProps; }) => void
>{ props: module.exports } : { props: MyComponentProps; }
>props : MyComponentProps
>module.exports : MyComponentProps
>module : { "\"tests/cases/compiler/input\"": MyComponentProps; }
>exports : MyComponentProps

8 changes: 4 additions & 4 deletions tests/baselines/reference/exportDefaultWithJSDoc1.types
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/

/** @type {NumberLike[]} */export default ([ ]);
>([ ]) : (string | number)[]
>([ ]) : NumberLike[]
>[ ] : undefined[]

=== tests/cases/compiler/b.ts ===
import A from './a'
>A : (string | number)[]
>A : import("tests/cases/compiler/a").NumberLike[]

A[0]
>A[0] : string | number
>A : (string | number)[]
>A[0] : import("tests/cases/compiler/a").NumberLike
>A : import("tests/cases/compiler/a").NumberLike[]
>0 : 0

8 changes: 4 additions & 4 deletions tests/baselines/reference/exportDefaultWithJSDoc2.types
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/

export default /** @type {NumberLike[]} */([ ]);
>([ ]) : (string | number)[]
>([ ]) : NumberLike[]
>[ ] : undefined[]

=== tests/cases/compiler/b.ts ===
import A from './a'
>A : (string | number)[]
>A : import("tests/cases/compiler/a").NumberLike[]

A[0]
>A[0] : string | number
>A : (string | number)[]
>A[0] : import("tests/cases/compiler/a").NumberLike
>A : import("tests/cases/compiler/a").NumberLike[]
>0 : 0

4 changes: 2 additions & 2 deletions tests/baselines/reference/jsDeclarationsEnumTag.types
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function consume(t,s,f) {
>consume : (t: Target, s: Second, f: Fs) => void
>t : string
>s : number
>f : (arg0: number) => number
>f : Fs

/** @type {string} */
var str = t
Expand All @@ -87,7 +87,7 @@ export function consume(t,s,f) {
/** @type {(n: number) => number} */
var fun = f
>fun : (n: number) => number
>f : (arg0: number) => number
>f : Fs

/** @type {Target} */
var v = Target.START
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ declare class Hook {
* @param {HookHandler} handle
*/
constructor(handle: HookHandler);
handle: (arg: import("./context")) => void;
handle: HookHandler;
}
declare namespace Hook {
export { HookHandler };
Expand Down
Loading