8000 Allow expressions in class extends clauses by ahejlsberg · Pull Request #3516 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

Allow expressions in class extends clauses #3516

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 18 commits into from
Jun 17, 2015
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Addressing more CR feedback
  • Loading branch information
ahejlsberg committed Jun 17, 2015
commit efcccaa4f8db014d1a5348b7d6f0340e9dd6e67f
28 changes: 16 additions & 12 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8973,16 +8973,16 @@ namespace ts {
checkDecorators(node);
}

function checkTypeArgumentConstraints(typeParameters: TypeParameter[], typeArguments: TypeNode[]) {
if (produceDiagnostics) {
for (let i = 0; i < typeParameters.length; i++) {
let constraint = getConstraintOfTypeParameter(typeParameters[i]);
if (constraint) {
let typeArgument = typeArguments[i];
checkTypeAssignableTo(getTypeFromTypeNode(typeArgument), constraint, typeArgument, Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
}
function checkTypeArgumentConstraints(typeParameters: TypeParameter[], typeArguments: TypeNode[]): boolean {
let result = true;
for (let i = 0; i < typeParameters.length; i++) {
let constraint = getConstraintOfTypeParameter(typeParameters[i]);
if (constraint) {
let typeArgument = typeArguments[i];
result = result && checkTypeAssignableTo(getTypeFromTypeNode(typeArgument), constraint, typeArgument, Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
}
}
return result;
}

function checkTypeReferenceNode(node: TypeReferenceNode | ExpressionWithTypeArguments) {
Expand All @@ -8991,9 +8991,11 @@ namespace ts {
if (type !== unknownType && node.typeArguments) {
// Do type argument local checks only if referenced type is successfully resolved
forEach(node.typeArguments, checkSourceElement);
let symbol = getNodeLinks(node).resolvedSymbol;
let typeParameters = symbol.flags & SymbolFlags.TypeAlias ? getSymbolLinks(symbol).typeParameters : (<TypeReference>type).target.localTypeParameters;
checkTypeArgumentConstraints(typeParameters, node.typeArguments);
if (produceDiagnostics) {
let symbol = getNodeLinks(node).resolvedSymbol;
let typeParameters = symbol.flags & SymbolFlags.TypeAlias ? getSymbolLinks(symbol).typeParameters : (<TypeReference>type).target.localTypeParameters;
checkTypeArgumentConstraints(typeParameters, node.typeArguments);
}
}
}

Expand Down Expand Up @@ -10595,7 +10597,9 @@ namespace ts {
if (baseTypeNode.typeArguments) {
forEach(baseTypeNode.typeArguments, checkSourceElement);
for (let constructor of getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments)) {
checkTypeArgumentConstraints(constructor.typeParameters, baseTypeNode.typeArguments);
if (!checkTypeArgumentConstraints(constructor.typeParameters, baseTypeNode.typeArguments)) {
break;
}
}
}
checkTypeAssignableTo(type, baseType, node.name || node, Diagnostics.Class_0_incorrectly_extends_base_class_1);
Expand Down
0