Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3d3dae0
Adds support for type parameter defaults
rbuckton Jan 14, 2017
442f540
Updated Promise and PromiseLike to use defaults
rbuckton Jan 14, 2017
25cb02e
Fix circularity check, simplify default type mapper
rbuckton Jan 14, 2017
ca16ba8
Added comments and additional circularity tests
rbuckton Jan 14, 2017
0b44a2c
Flexible declaration merging
rbuckton Jan 19, 2017
0500065
Avoid inference for fully-supplied type arguments
rbuckton Jan 20, 2017
5ff0f81
Diagnostic message punctuation
rbuckton Jan 20, 2017
a2be5e2
Report error using type parameter from merged declaration
rbuckton Jan 21, 2017
fd228a9
Remove partial inference
rbuckton Jan 21, 2017
6b2c8cb
Defaults for type aliases
rbuckton Jan 21, 2017
76ba6a7
Merge branch 'master' into genericDefaults
rbuckton Jan 21, 2017
15232fe
Remove circular default check
rbuckton Jan 24, 2017
f5f1c7e
Merge branch 'genericDefaults' of https://github.com/Microsoft/TypeSc…
rbuckton Jan 24, 2017
febde3f
Revert noConstraintType name change
rbuckton Jan 24, 2017
b58ef9e
Merge branch 'master' into genericDefaults
rbuckton Jan 30, 2017
7616e37
Use length() throught checker
rbuckton Jan 30, 2017
e001258
Move non-local type parameter check to resolveName
rbuckton Jan 30, 2017
9ba2a6b
Skip type parameters.
rbuckton Feb 1, 2017
6091050
Remove pre-computation of minTypeArgumentCount
rbuckton Feb 3, 2017
6ffcbf5
Merge branch 'master' into genericDefaults
rbuckton Feb 3, 2017
5bb2fe0
Simplify checkTypeParameterListsIdentical
rbuckton Feb 4, 2017
96181c0
Shortcut for class/namespace merge
rbuckton Feb 4, 2017
23216f9
Merge branch 'master' into genericDefaults
rbuckton Feb 15, 2017
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
Prev Previous commit
Next Next commit
Report error using type parameter from merged declaration
  • Loading branch information
rbuckton committed Jan 21, 2017
commit a2be5e263a6d9c0095cec6f2b710588b6b4461bc
18 changes: 18 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17594,6 +17594,11 @@ namespace ts {
error(node.name, Diagnostics.All_declarations_of_0_must_have_identical_modifiers, declarationNameToString(node.name));
}
}
if (type.flags & TypeFlags.TypeParameter && !(<TypeParameter>type).isThisType && type.symbol) {
if (!isTypeParameterInScope(<TypeParameter>type, node)) {
error(node.name, Diagnostics.Type_parameter_0_cannot_be_referenced_outside_of_a_declaration_that_defines_it, symbolToString(type.symbol));
}
}
if (node.kind !== SyntaxKind.PropertyDeclaration && node.kind !== SyntaxKind.PropertySignature) {
// We know we don't have a binding pattern or computed name here
checkExportsOnMergedDeclarations(node);
Expand All @@ -17608,6 +17613,19 @@ namespace ts {
}
}

function isTypeParameterInScope(typeParameter: TypeParameter, node: Node) {
const parents = map(filter(typeParameter.symbol.declarations, isTypeParameter), node => node.parent);
while (node) {
if (isFunctionLike(node) || isClassLike(node) || node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.TypeAliasDeclaration) {
if (contains(parents, node)) {
return true;
}
}
node = node.parent;
}
return false;
}

function areDeclarationFlagsIdentical(left: Declaration, right: Declaration) {
if ((left.kind === SyntaxKind.Parameter && right.kind === SyntaxKind.VariableDeclaration) ||
(left.kind === SyntaxKind.VariableDeclaration && right.kind === SyntaxKind.Parameter)) {
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,10 @@
"category": "Error",
"code": 2366
},
"Type parameter '{0}' cannot be referenced outside of a declaration that defines it.": {
"category": "Error",
"code": 2367
},
"Type parameter name cannot be '{0}'": {
"category": "Error",
"code": 2368
Expand Down
10 changes: 8 additions & 2 deletions tests/baselines/reference/genericDefaultsErrors.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ tests/cases/compiler/genericDefaultsErrors.ts(35,32): error TS2344: Type 'number
tests/cases/compiler/genericDefaultsErrors.ts(38,15): error TS2707: Generic type 'i09<T, U, V>' requires between 2 and 3 type arguments.
tests/cases/compiler/genericDefaultsErrors.ts(39,15): error TS2707: Generic type 'i09<T, U, V>' requires between 2 and 3 type arguments.
tests/cases/compiler/genericDefaultsErrors.ts(42,15): error TS2707: Generic type 'i09<T, U, V>' requires between 2 and 3 type arguments.
tests/cases/compiler/genericDefaultsErrors.ts(44,17): error TS2367: Type parameter 'T' cannot be referenced outside of a declaration that defines it.


==== tests/cases/compiler/genericDefaultsErrors.ts (31 errors) ====
==== tests/cases/compiler/genericDefaultsErrors.ts (32 errors) ====

declare const x: any;

Expand Down Expand Up @@ -139,4 +140,9 @@ tests/cases/compiler/genericDefaultsErrors.ts(42,15): error TS2707: Generic type
type i09t03 = i09<1, 2, 3>; // ok
type i09t04 = i09<1, 2, 3, 4>; // error
~~~~~~~~~~~~~~~
!!! error TS2707: Generic type 'i09<T, U, V>' requires between 2 and 3 type arguments.
!!! error TS2707: Generic type 'i09<T, U, V>' requires between 2 and 3 type arguments.

interface i10 { x: T; } // error
~
!!! error TS2367: Type parameter 'T' cannot be referenced outside of a declaration that defines it.
interface i10<T = number> {}
10 changes: 9 additions & 1 deletion tests/baselines/reference/genericDefaultsErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ type i09t00 = i09; // error
type i09t01 = i09<1>; // error
type i09t02 = i09<1, 2>; // ok
type i09t03 = i09<1, 2, 3>; // ok
type i09t04 = i09<1, 2, 3, 4>; // error
type i09t04 = i09<1, 2, 3, 4>; // error

interface i10 { x: T; } // error
interface i10<T = number> {}

//// [genericDefaultsErrors.js]
f11(); // ok
Expand Down Expand Up @@ -101,3 +104,8 @@ declare type i09t01 = i09<1>;
declare type i09t02 = i09<1, 2>;
declare type i09t03 = i09<1, 2, 3>;
declare type i09t04 = i09<1, 2, 3, 4>;
interface i10 {
x: T;
}
interface i10<T = number> {
}
5 changes: 4 additions & 1 deletion tests/cases/compiler/genericDefaultsErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ type i09t00 = i09; // error
type i09t01 = i09<1>; // error
type i09t02 = i09<1, 2>; // ok
type i09t03 = i09<1, 2, 3>; // ok
type i09t04 = i09<1, 2, 3, 4>; // error
type i09t04 = i09<1, 2, 3, 4>; // error

interface i10 { x: T; } // error
interface i10<T = number> {}