Skip to content

Commit

Permalink
Create type aliases for unresolved type symbols (#45976)
Browse files Browse the repository at this point in the history
* Create type aliases for unresolved type symbols

* Accept new baselines

* Update fourslash tests

* Unresolved import aliases create tagged unresolved symbols

* Add comments

* Accept new baselines

* Add fourslash tests
  • Loading branch information
ahejlsberg authored Sep 23, 2021
1 parent 0396723 commit a4f9bf0
Show file tree
Hide file tree
Showing 443 changed files with 10,964 additions and 6,380 deletions.
180 changes: 121 additions & 59 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4957,6 +4957,7 @@ namespace ts {
HasNeverType = 1 << 17, // Synthetic property with at least one never type in constituents
Mapped = 1 << 18, // Property of mapped type
StripOptional = 1 << 19, // Strip optionality in mapped property
Unresolved = 1 << 20, // Unresolved type alias symbol
Synthetic = SyntheticProperty | SyntheticMethod,
Discriminant = HasNonUniformType | HasLiteralType,
Partial = ReadPartial | WritePartial
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ArrowFunction1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
var v = (a: ) => {
>v : Symbol(v, Decl(ArrowFunction1.ts, 0, 3))
>a : Symbol(a, Decl(ArrowFunction1.ts, 0, 9))
> : Symbol(unknown)

};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module clodule1 {
function f(x: T) { }
>f : Symbol(f, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 8, 17))
>x : Symbol(x, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 9, 15))
>T : Symbol(T)
}

class clodule2<T>{
Expand All @@ -38,10 +39,12 @@ module clodule2 {

var x: T;
>x : Symbol(x, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 19, 7))
>T : Symbol(T)

class D<U extends T>{
>D : Symbol(D, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 19, 13))
>U : Symbol(U, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 21, 12))
>T : Symbol(T)

id: string;
>id : Symbol(D.id, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 21, 25))
Expand Down Expand Up @@ -92,6 +95,7 @@ module clodule4 {

name: T;
>name : Symbol(D.name, Decl(ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.ts, 44, 13))
>T : Symbol(T)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module clodule1 {
>clodule1 : typeof clodule1

function f(x: T) { }
>f : (x: any) => void
>x : any
>f : (x: T) => void
>x : T
}

class clodule2<T>{
Expand All @@ -33,7 +33,7 @@ module clodule2 {
>clodule2 : typeof clodule2

var x: T;
>x : any
>x : T

class D<U extends T>{
>D : D<U>
Expand Down Expand Up @@ -83,7 +83,7 @@ module clodule4 {
>D : D

name: T;
>name : any
>name : T
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ function * foo() {
// Legal to use 'yield' in a type context.
var v: yield;
>v : Symbol(v, Decl(FunctionDeclaration13_es6.ts, 2, 6))
>yield : Symbol(yield)
}

2 changes: 1 addition & 1 deletion tests/baselines/reference/FunctionDeclaration13_es6.types
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ function * foo() {

// Legal to use 'yield' in a type context.
var v: yield;
>v : any
>v : yield
}

1 change: 1 addition & 0 deletions tests/baselines/reference/ParameterList5.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
function A(): (public B) => C {
>A : Symbol(A, Decl(ParameterList5.ts, 0, 0))
>B : Symbol(B, Decl(ParameterList5.ts, 0, 15))
>C : Symbol(C)
}
2 changes: 1 addition & 1 deletion tests/baselines/reference/ParameterList5.types
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=== tests/cases/compiler/ParameterList5.ts ===
function A(): (public B) => C {
>A : () => (B: any) => any
>A : () => (B: any) => C
>B : any
}
1 change: 1 addition & 0 deletions tests/baselines/reference/TupleType6.symbols
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
=== tests/cases/conformance/parser/ecmascript5/TupleTypes/TupleType6.ts ===
var v: [number,,]
>v : Symbol(v, Decl(TupleType6.ts, 0, 3))
> : Symbol(unknown)

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export module A {
// collision with 'Origin' var in other part of merged module
export var Origin: Point = { x: 0, y: 0 };
>Origin : Symbol(Origin, Decl(part2.ts, 2, 14))
>Point : Symbol(Point)
>x : Symbol(x, Decl(part2.ts, 2, 32))
>y : Symbol(y, Decl(part2.ts, 2, 38))

Expand All @@ -59,7 +60,9 @@ export module A {

constructor(public tl: Point, public br: Point) { }
>tl : Symbol(Plane.tl, Decl(part2.ts, 6, 24))
>Point : Symbol(Point)
>br : Symbol(Plane.br, Decl(part2.ts, 6, 41))
>Point : Symbol(Point)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export module A {

// collision with 'Origin' var in other part of merged module
export var Origin: Point = { x: 0, y: 0 };
>Origin : any
>Origin : Point
>{ x: 0, y: 0 } : { x: number; y: number; }
>x : number
>0 : 0
Expand All @@ -59,8 +59,8 @@ export module A {
>Plane : Plane

constructor(public tl: Point, public br: Point) { }
>tl : any
>br : any
>tl : Point
>br : Point
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export class Q {
set bet(arg: DoesNotExist) {}
>bet : Symbol(Q.bet, Decl(accessorDeclarationEmitVisibilityErrors.ts, 0, 16))
>arg : Symbol(arg, Decl(accessorDeclarationEmitVisibilityErrors.ts, 1, 12))
>DoesNotExist : Symbol(DoesNotExist)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export class Q {
>Q : Q

set bet(arg: DoesNotExist) {}
>bet : any
>arg : any
>bet : DoesNotExist
>arg : DoesNotExist
}
1 change: 1 addition & 0 deletions tests/baselines/reference/aliasBug.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function use() {
var p3:booz.bar;
>p3 : Symbol(p3, Decl(aliasBug.ts, 15, 5))
>booz : Symbol(booz, Decl(aliasBug.ts, 7, 21))
>bar : Symbol(booz.bar)

var p22 = new provide.Provide();
>p22 : Symbol(p22, Decl(aliasBug.ts, 16, 5))
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/aliasBug.types
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function use() {
>foo : any

var p3:booz.bar;
>p3 : any
>p3 : booz.bar
>booz : any

var p22 = new provide.Provide();
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/aliasErrors.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function use() {
var p3:booz.bar;
>p3 : Symbol(p3, Decl(aliasErrors.ts, 25, 5))
>booz : Symbol(booz, Decl(aliasErrors.ts, 6, 21))
>bar : Symbol(booz.bar)

var p22 = new provide.Provide();
>p22 : Symbol(p22, Decl(aliasErrors.ts, 26, 5))
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/aliasErrors.types
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function use() {
>foo : any

var p3:booz.bar;
>p3 : any
>p3 : booz.bar
>booz : any

var p22 = new provide.Provide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ originalZZZ;

const y: originalZZZ = x;
>y : Symbol(y, Decl(index.ts, 8, 5))
>originalZZZ : Symbol(originalZZZ)
>x : Symbol(x, Decl(index.ts, 2, 5))

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ originalZZZ;
>originalZZZ : 123

const y: originalZZZ = x;
>y : any
>y : originalZZZ
>x : zzz

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ declare module "OuterModule" {
public x: m2.c;
>x : Symbol(SubModule.x, Decl(ambientExternalModuleWithRelativeExternalImportDeclaration.ts, 4, 35))
>m2 : Symbol(m2, Decl(ambientExternalModuleWithRelativeExternalImportDeclaration.ts, 0, 30))
>c : Symbol(m2)
>c : Symbol(m2.c)

constructor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declare module "OuterModule" {
>InstanceVar : number

public x: m2.c;
>x : any
>x : m2.c
>m2 : any

constructor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ assertEqual(animal.type, 'cat' as const);
>animal.type : Symbol(type, Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 0, 15), Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 5, 15))
>animal : Symbol(animal, Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 14, 5))
>type : Symbol(type, Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 0, 15), Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 5, 15))
>const : Symbol(const)

animal.canMeow; // since is cat, should not be an error
>animal.canMeow : Symbol(Cat.canMeow, Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 1, 16))
Expand All @@ -61,6 +62,7 @@ assertEqual(animalOrUndef?.type, 'cat' as const);
>animalOrUndef?.type : Symbol(type, Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 0, 15), Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 5, 15))
>animalOrUndef : Symbol(animalOrUndef, Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 19, 5))
>type : Symbol(type, Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 0, 15), Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 5, 15))
>const : Symbol(const)

animalOrUndef.canMeow; // since is cat, should not be an error
>animalOrUndef.canMeow : Symbol(Cat.canMeow, Decl(assertionFunctionsCanNarrowByDiscriminant.ts, 1, 16))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Derived2 extends Derived { baz: string; }

var a: A;
>a : Symbol(a, Decl(assignmentCompatWithStringIndexer3.ts, 6, 3))
>A : Symbol(A)

var b1: { [x: string]: string; }
>b1 : Symbol(b1, Decl(assignmentCompatWithStringIndexer3.ts, 7, 3))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ interface Derived2 extends Derived { baz: string; }
>baz : string

var a: A;
>a : any
>a : A

var b1: { [x: string]: string; }
>b1 : { [x: string]: string; }
>x : string

a = b1; // error
>a = b1 : { [x: string]: string; }
>a : any
>a : A
>b1 : { [x: string]: string; }

b1 = a; // error
>b1 = a : any
>b1 = a : A
>b1 : { [x: string]: string; }
>a : any
>a : A

module Generics {
>Generics : typeof Generics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ var foo = async (): Promise<void> => {
// Legal to use 'await' in a type context.
var v: await;
>v : Symbol(v, Decl(asyncArrowFunction10_es2017.ts, 2, 6))
>await : Symbol(await)
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ var foo = async (): Promise<void> => {

// Legal to use 'await' in a type context.
var v: await;
>v : any
>v : await
}

1 change: 1 addition & 0 deletions tests/baselines/reference/asyncArrowFunction10_es5.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ var foo = async (): Promise<void> => {
// Legal to use 'await' in a type context.
var v: await;
>v : Symbol(v, Decl(asyncArrowFunction10_es5.ts, 2, 6))
>await : Symbol(await)
}

2 changes: 1 addition & 1 deletion tests/baselines/reference/asyncArrowFunction10_es5.types
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ var foo = async (): Promise<void> => {

// Legal to use 'await' in a type context.
var v: await;
>v : any
>v : await
}

1 change: 1 addition & 0 deletions tests/baselines/reference/asyncArrowFunction10_es6.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ var foo = async (): Promise<void> => {
// Legal to use 'await' in a type context.
var v: await;
>v : Symbol(v, Decl(asyncArrowFunction10_es6.ts, 2, 6))
>await : Symbol(await)
}

2 changes: 1 addition & 1 deletion tests/baselines/reference/asyncArrowFunction10_es6.types
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ var foo = async (): Promise<void> => {

// Legal to use 'await' in a type context.
var v: await;
>v : any
>v : await
}

Loading

0 comments on commit a4f9bf0

Please sign in to comment.