Skip to content

Deferred resolution of object literal members to support recursive types.#550

Merged
ahejlsberg merged 4 commits intomasterfrom
deferredTypeLiterals
Sep 3, 2014
Merged

Deferred resolution of object literal members to support recursive types.#550
ahejlsberg merged 4 commits intomasterfrom
deferredTypeLiterals

Conversation

@ahejlsberg
Copy link
Member

Fixes #523.

With this change the following declarations all create recursive types:

var a: { x: typeof a; };
var b: () => typeof b;
var c: { (): typeof c; };
var d: { [s: string]: typeof d; };

@vladima
Copy link
Contributor

vladima commented Aug 27, 2014

👍

@CyrusNajmabadi
Copy link
Contributor

Are there any back compat concerns here? Or does this preserve behavior between V1 and the current impl? Thanks!

@ahejlsberg
Copy link
Member Author

For the declarations

var a: { x: typeof a; };
var b: () => typeof b;
var c: { (): typeof c; };
var d: { [s: string]: typeof d; };

the old compiler would generate the types

var a: { x: any; };
var b: () => any;
var c: { (): any; };
var d: { [s: string]: any; };

whereas the new compiler correctly generates recursive types. Technically the new behavior is stricter, but the old behavior is basically a bug (i.e. the spec never says that typeof should become an any). I very much doubt this will affect any existing code, but if it does, it is likely because that code had a type error in it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment not needed

@JsonFreeman
Copy link
Contributor

Please also test that this works in parameters, type parameter constraints, and type arguments.

And I suppose eventually we will want to test tuple element types as well.

ahejlsberg added a commit that referenced this pull request Sep 3, 2014
Deferred resolution of object literal members to support recursive types.
@ahejlsberg ahejlsberg merged commit dab3691 into master Sep 3, 2014
@ahejlsberg ahejlsberg deleted the deferredTypeLiterals branch September 3, 2014 18:03
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[typeBaselines] Recursive type gets erased to any immediately

4 participants