Skip to content
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 @@ -5864,7 +5864,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

// Verify if the symbol is accessible
return (symbol && hasVisibleDeclarations(symbol, shouldComputeAliasToMakeVisible)) || {
accessibility: SymbolAccessibility.NotAccessible,
accessibility: SymbolAccessibility.NotResolved,
errorSymbolName: getTextOfNode(firstIdentifier),
errorNode: firstIdentifier,
};
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ export function transformDeclarations(context: TransformationContext) {
}
// TODO: Do all these accessibility checks inside/after the first pass in the checker when declarations are enabled, if possible
}
else {
// The checker should issue errors on unresolvable names, skip the declaration emit error for using a private/unreachable name for those
else if (symbolAccessibilityResult.accessibility !== SymbolAccessibility.NotResolved) {
// Report error
const errorInfo = getSymbolAccessibilityDiagnostic(symbolAccessibilityResult);
if (errorInfo) {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5544,6 +5544,7 @@ export const enum SymbolAccessibility {
Accessible,
NotAccessible,
CannotBeNamed,
NotResolved,
}

/** @internal */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
accessorDeclarationEmitVisibilityErrors.ts(2,18): error TS2304: Cannot find name 'DoesNotExist'.
accessorDeclarationEmitVisibilityErrors.ts(2,18): error TS4106: Parameter 'arg' of accessor has or is using private name 'DoesNotExist'.


==== accessorDeclarationEmitVisibilityErrors.ts (2 errors) ====
==== accessorDeclarationEmitVisibilityErrors.ts (1 errors) ====
export class Q {
set bet(arg: DoesNotExist) {}
~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'DoesNotExist'.
~~~~~~~~~~~~
!!! error TS4106: Parameter 'arg' of accessor has or is using private name 'DoesNotExist'.
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ export class Q {
export class Q {
set bet(arg) { }
}


//// [accessorDeclarationEmitVisibilityErrors.d.ts]
export declare class Q {
set bet(arg: DoesNotExist);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
declarationEmitExpressionInExtends4.ts(5,17): error TS2315: Type 'D' is not generic.
declarationEmitExpressionInExtends4.ts(9,18): error TS2304: Cannot find name 'SomeUndefinedFunction'.
declarationEmitExpressionInExtends4.ts(14,18): error TS2304: Cannot find name 'SomeUndefinedFunction'.
declarationEmitExpressionInExtends4.ts(14,18): error TS4020: 'extends' clause of exported class 'C3' has or is using private name 'SomeUndefinedFunction'.


==== declarationEmitExpressionInExtends4.ts (4 errors) ====
==== declarationEmitExpressionInExtends4.ts (3 errors) ====
function getSomething() {
return class D { }
}
Expand All @@ -25,7 +24,5 @@ declarationEmitExpressionInExtends4.ts(14,18): error TS4020: 'extends' clause of
class C3 extends SomeUndefinedFunction {
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'SomeUndefinedFunction'.
~~~~~~~~~~~~~~~~~~~~~
!!! error TS4020: 'extends' clause of exported class 'C3' has or is using private name 'SomeUndefinedFunction'.

}
16 changes: 16 additions & 0 deletions tests/baselines/reference/declarationEmitExpressionInExtends4.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,19 @@ var C3 = /** @class */ (function (_super) {
}
return C3;
}(SomeUndefinedFunction));


//// [declarationEmitExpressionInExtends4.d.ts]
declare function getSomething(): {
new (): {};
};
declare const C_base: {
new (): {};
};
declare class C extends C_base<number, string> {
}
declare const C2_base: any;
declare class C2 extends C2_base<number, string> {
}
declare class C3 extends SomeUndefinedFunction {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
declarationEmitExpressionInExtends7.ts(1,30): error TS2304: Cannot find name 'SomeUndefinedFunction'.
declarationEmitExpressionInExtends7.ts(1,30): error TS4021: 'extends' clause of exported class has or is using private name 'SomeUndefinedFunction'.


==== declarationEmitExpressionInExtends7.ts (2 errors) ====
==== declarationEmitExpressionInExtends7.ts (1 errors) ====
export default class extends SomeUndefinedFunction {}
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'SomeUndefinedFunction'.
~~~~~~~~~~~~~~~~~~~~~
!!! error TS4021: 'extends' clause of exported class has or is using private name 'SomeUndefinedFunction'.

Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ var default_1 = /** @class */ (function (_super) {
return default_1;
}(SomeUndefinedFunction));
exports.default = default_1;


//// [declarationEmitExpressionInExtends7.d.ts]
export default class extends SomeUndefinedFunction {
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
declarationEmitIndexTypeNotFound.ts(2,6): error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
declarationEmitIndexTypeNotFound.ts(2,13): error TS2304: Cannot find name 'TypeNotFound'.
declarationEmitIndexTypeNotFound.ts(2,13): error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'.


==== declarationEmitIndexTypeNotFound.ts (3 errors) ====
==== declarationEmitIndexTypeNotFound.ts (2 errors) ====
export interface Test {
[index: TypeNotFound]: any;
~~~~~
!!! error TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'TypeNotFound'.
~~~~~~~~~~~~
!!! error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'.
}

6 changes: 6 additions & 0 deletions tests/baselines/reference/declarationEmitIndexTypeNotFound.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ export interface Test {
//// [declarationEmitIndexTypeNotFound.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


//// [declarationEmitIndexTypeNotFound.d.ts]
export interface Test {
[index: TypeNotFound]: any;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
declarationEmitInvalidExport.ts(4,30): error TS4081: Exported type alias 'MyClass' has or is using private name 'myClass'.
declarationEmitInvalidExport.ts(5,1): error TS1128: Declaration or statement expected.


==== declarationEmitInvalidExport.ts (2 errors) ====
==== declarationEmitInvalidExport.ts (1 errors) ====
if (false) {
export var myClass = 0;
}
export type MyClass = typeof myClass;
~~~~~~~
!!! error TS4081: Exported type alias 'MyClass' has or is using private name 'myClass'.
Copy link
Member Author

Choose a reason for hiding this comment

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

Declaration emit errors are emitted in the presence of parse errors (unlike checker errors), so this (pretty bogus, given the parse error) error was here before, and now it's gone. If checker errors were reported, there would be one on myClass here, but, again, blocked by a parse error anyway.

}
~
!!! error TS1128: Declaration or statement expected.
Expand Down
4 changes: 4 additions & 0 deletions tests/baselines/reference/declarationEmitInvalidExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
if (false) {
exports.myClass = 0;
}


//// [declarationEmitInvalidExport.d.ts]
export type MyClass = typeof myClass;
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
declarationEmitLambdaWithMissingTypeParameterNoCrash.ts(2,27): error TS2304: Cannot find name 'T2'.
declarationEmitLambdaWithMissingTypeParameterNoCrash.ts(2,27): error TS4016: Type parameter 'T1' of exported function has or is using private name 'T2'.
declarationEmitLambdaWithMissingTypeParameterNoCrash.ts(3,33): error TS2304: Cannot find name 'T2'.
declarationEmitLambdaWithMissingTypeParameterNoCrash.ts(3,33): error TS4006: Type parameter 'T1' of constructor signature from exported interface has or is using private name 'T2'.


==== declarationEmitLambdaWithMissingTypeParameterNoCrash.ts (4 errors) ====
==== declarationEmitLambdaWithMissingTypeParameterNoCrash.ts (2 errors) ====
export interface Foo {
preFetch: <T1 extends T2> (c: T1) => void; // Type T2 is not defined
~~
!!! error TS2304: Cannot find name 'T2'.
~~
!!! error TS4016: Type parameter 'T1' of exported function has or is using private name 'T2'.
preFetcher: new <T1 extends T2> (c: T1) => void; // Type T2 is not defined
~~
!!! error TS2304: Cannot find name 'T2'.
~~
!!! error TS4006: Type parameter 'T1' of constructor signature from exported interface has or is using private name 'T2'.
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ export interface Foo {
//// [declarationEmitLambdaWithMissingTypeParameterNoCrash.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


//// [declarationEmitLambdaWithMissingTypeParameterNoCrash.d.ts]
export interface Foo {
preFetch: <T1 extends T2>(c: T1) => void;
preFetcher: new <T1 extends T2>(c: T1) => void;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/FromFactor.ts(2,15): error TS2304: Cannot find name 'StringKeyOf'.
/FromFactor.ts(2,15): error TS4103: Type parameter 'TName' of exported mapped object type is using private name 'StringKeyOf'.


==== /Helpers.ts (0 errors) ====
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;

==== /FromFactor.ts (2 errors) ====
==== /FromFactor.ts (1 errors) ====
export type RowToColumns<TColumns> = {
[TName in StringKeyOf<TColumns>]: any;
~~~~~~~~~~~
!!! error TS2304: Cannot find name 'StringKeyOf'.
~~~~~~~~~~~
!!! error TS4103: Type parameter 'TName' of exported mapped object type is using private name 'StringKeyOf'.
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });

//// [Helpers.d.ts]
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
//// [FromFactor.d.ts]
export type RowToColumns<TColumns> = {
[TName in StringKeyOf<TColumns>]: any;
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts(1,18): error TS2304: Cannot find name 'Unknown'.
declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts(1,18): error TS4083: Type parameter 'T' of exported type alias has or is using private name 'Unknown'.


==== declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts (2 errors) ====
==== declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.ts (1 errors) ====
type A<T extends Unknown> = {}
~~~~~~~
!!! error TS2304: Cannot find name 'Unknown'.
~~~~~~~
!!! error TS4083: Type parameter 'T' of exported type alias has or is using private name 'Unknown'.
!!! error TS2304: Cannot find name 'Unknown'.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
type A<T extends Unknown> = {}

//// [declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.js]


//// [declarationEmitTypeAliasTypeParameterExtendingUnknownSymbol.d.ts]
type A<T extends Unknown> = {};
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
declarationEmitUnknownImport.ts(1,1): error TS2303: Circular definition of import alias 'Foo'.
declarationEmitUnknownImport.ts(1,14): error TS2304: Cannot find name 'SomeNonExistingName'.
declarationEmitUnknownImport.ts(1,14): error TS2503: Cannot find namespace 'SomeNonExistingName'.
declarationEmitUnknownImport.ts(1,14): error TS4000: Import declaration 'Foo' is using private name 'SomeNonExistingName'.


==== declarationEmitUnknownImport.ts (4 errors) ====
==== declarationEmitUnknownImport.ts (3 errors) ====
import Foo = SomeNonExistingName
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2303: Circular definition of import alias 'Foo'.
~~~~~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'SomeNonExistingName'.
~~~~~~~~~~~~~~~~~~~
!!! error TS2503: Cannot find namespace 'SomeNonExistingName'.
~~~~~~~~~~~~~~~~~~~
!!! error TS4000: Import declaration 'Foo' is using private name 'SomeNonExistingName'.
export {Foo}
5 changes: 5 additions & 0 deletions tests/baselines/reference/declarationEmitUnknownImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.Foo = void 0;
var Foo = SomeNonExistingName;
exports.Foo = Foo;


//// [declarationEmitUnknownImport.d.ts]
import Foo = SomeNonExistingName;
export { Foo };
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ declarationEmitUnknownImport2.ts(1,1): error TS2303: Circular definition of impo
declarationEmitUnknownImport2.ts(1,12): error TS1005: '=' expected.
declarationEmitUnknownImport2.ts(1,12): error TS2304: Cannot find name 'From'.
declarationEmitUnknownImport2.ts(1,12): error TS2503: Cannot find namespace 'From'.
declarationEmitUnknownImport2.ts(1,12): error TS4000: Import declaration 'Foo' is using private name 'From'.
declarationEmitUnknownImport2.ts(1,17): error TS1005: ';' expected.


==== declarationEmitUnknownImport2.ts (6 errors) ====
==== declarationEmitUnknownImport2.ts (5 errors) ====
import Foo From './Foo'; // Syntax error
~~~~~~~~~~~~~~~
!!! error TS2303: Circular definition of import alias 'Foo'.
Expand All @@ -16,8 +15,6 @@ declarationEmitUnknownImport2.ts(1,17): error TS1005: ';' expected.
!!! error TS2304: Cannot find name 'From'.
~~~~
!!! error TS2503: Cannot find namespace 'From'.
~~~~
!!! error TS4000: Import declaration 'Foo' is using private name 'From'.
~~~~~~~
!!! error TS1005: ';' expected.
export default Foo
5 changes: 5 additions & 0 deletions tests/baselines/reference/declarationEmitUnknownImport2.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
var Foo = From;
'./Foo'; // Syntax error
exports.default = Foo;


//// [declarationEmitUnknownImport2.d.ts]
import Foo = From;
export default Foo;
5 changes: 1 addition & 4 deletions tests/baselines/reference/genericDefaultsErrors.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ genericDefaultsErrors.ts(32,15): error TS2707: Generic type 'i09<T, U, V>' requi
genericDefaultsErrors.ts(33,15): error TS2707: Generic type 'i09<T, U, V>' requires between 2 and 3 type arguments.
genericDefaultsErrors.ts(36,15): error TS2707: Generic type 'i09<T, U, V>' requires between 2 and 3 type arguments.
genericDefaultsErrors.ts(38,20): error TS2304: Cannot find name 'T'.
genericDefaultsErrors.ts(38,20): error TS4033: Property 'x' of exported interface has or is using private name 'T'.
genericDefaultsErrors.ts(42,29): error TS2716: Type parameter 'T' has a circular default.


==== genericDefaultsErrors.ts (22 errors) ====
==== genericDefaultsErrors.ts (21 errors) ====
declare const x: any;

declare function f03<T extends string = number>(): void; // error
Expand Down Expand Up @@ -111,8 +110,6 @@ genericDefaultsErrors.ts(42,29): error TS2716: Type parameter 'T' has a circular
interface i10 { x: T; } // error
~
!!! error TS2304: Cannot find name 'T'.
~
!!! error TS4033: Property 'x' of exported interface has or is using private name 'T'.
interface i10<T = number> {}

// https://github.com/Microsoft/TypeScript/issues/16221
Expand Down
42 changes: 42 additions & 0 deletions tests/baselines/reference/genericDefaultsErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,45 @@ f11(); // ok
f11(); // error
f12(); // ok
f12("a"); // error


//// [genericDefaultsErrors.d.ts]
declare const x: any;
declare function f03<T extends string = number>(): void;
declare function f04<T extends string, U extends number = T>(): void;
declare function f05<T, U extends number = T>(): void;
declare function f06<T, U extends T = number>(): void;
declare function f11<T, U, V = number>(): void;
declare function f12<T, U = T>(a?: U): void;
interface i00<T> {
}
interface i00<U = number> {
}
interface i01<T = number> {
}
interface i01<T = string> {
}
interface i04<T = number, U> {
}
interface i05<T extends string = number> {
}
interface i06<T extends string, U extends number = T> {
}
interface i07<T, U extends number = T> {
}
interface i08<T, U extends T = number> {
}
interface i09<T, U, V = number> {
}
type i09t00 = i09;
type i09t01 = i09<1>;
type i09t02 = i09<1, 2>;
type i09t03 = i09<1, 2, 3>;
type i09t04 = i09<1, 2, 3, 4>;
interface i10 {
x: T;
}
interface i10<T = number> {
}
interface SelfReference<T = SelfReference> {
}
Loading