Skip to content

Adds support for type parameter defaults #13487

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 23 commits into from
Feb 15, 2017
Merged
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
Revert noConstraintType name change
  • Loading branch information
rbuckton committed Jan 24, 2017
commit febde3fabc14464de9986f8247997839a59397f9
30 changes: 15 additions & 15 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ namespace ts {
// in getPropagatingFlagsOfTypes, and it is checked in inferFromTypes.
anyFunctionType.flags |= TypeFlags.ContainsAnyFunctionType;

const noConstraintOrDefaultType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
const circularConstraintOrDefaultType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
const circularConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);

const anySignature = createSignature(undefined, undefined, 0, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
const unknownSignature = createSignature(undefined, undefined, 0, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false);
Expand Down Expand Up @@ -4791,11 +4791,11 @@ namespace ts {

function getBaseConstraintOfType(type: TypeVariable | UnionOrIntersectionType): Type {
const constraint = getResolvedBaseConstraint(type);
return constraint !== noConstraintOrDefaultType && constraint !== circularConstraintOrDefaultType ? constraint : undefined;
return constraint !== noConstraintType && constraint !== circularConstraintType ? constraint : undefined;
}

function hasNonCircularBaseConstraint(type: TypeVariable): boolean {
return getResolvedBaseConstraint(type) !== circularConstraintOrDefaultType;
return getResolvedBaseConstraint(type) !== circularConstraintType;
}

/**
Expand All @@ -4809,7 +4809,7 @@ namespace ts {
if (!type.resolvedBaseConstraint) {
typeStack = [];
const constraint = getBaseConstraint(type);
type.resolvedBaseConstraint = circular ? circularConstraintOrDefaultType : getTypeWithThisArgument(constraint || noConstraintOrDefaultType, type);
type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type);
}
return type.resolvedBaseConstraint;

Expand Down Expand Up @@ -4869,14 +4869,14 @@ namespace ts {
if (!typeParameter.default) {
if (typeParameter.target) {
const targetDefault = getDefaultFromTypeParameter(typeParameter.target);
typeParameter.default = targetDefault ? instantiateType(targetDefault, typeParameter.mapper) : noConstraintOrDefaultType;
typeParameter.default = targetDefault ? instantiateType(targetDefault, typeParameter.mapper) : noConstraintType;
}
else {
const defaultDeclaration = typeParameter.symbol && forEach(typeParameter.symbol.declarations, decl => isTypeParameter(decl) && decl.default);
typeParameter.default = defaultDeclaration ? getTypeFromTypeNode(defaultDeclaration) : noConstraintOrDefaultType;
typeParameter.default = defaultDeclaration ? getTypeFromTypeNode(defaultDeclaration) : noConstraintType;
Copy link
Member

Choose a reason for hiding this comment

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

This is a little confusing - so if there were any circular types in a union, you return undefined. But you disregard all circularities in an intersection type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reused this from line 4827, above. It does seem like it should also be performing a comparison against types.length as well, however I am unsure as to whether there was a specific reason for 4827 to ignore circularity in an intersection type.

Copy link
Contributor Author

@rbuckton rbuckton Jan 14, 2017

Choose a reason for hiding this comment

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

I made this more consistent in 25cb02e and I've added some additional circularity tests in ca16ba8.

}
}
return typeParameter.default === noConstraintOrDefaultType ? undefined : typeParameter.default;
return typeParameter.default === noConstraintType ? undefined : typeParameter.default;
}

/**
Expand Down Expand Up @@ -5497,14 +5497,14 @@ namespace ts {
if (!typeParameter.constraint) {
if (typeParameter.target) {
const targetConstraint = getConstraintOfTypeParameter(typeParameter.target);
typeParameter.constraint = targetConstraint ? instantiateType(targetConstraint, typeParameter.mapper) : noConstraintOrDefaultType;
typeParameter.constraint = targetConstraint ? instantiateType(targetConstraint, typeParameter.mapper) : noConstraintType;
}
else {
const constraintDeclaration = getConstraintDeclaration(typeParameter);
typeParameter.constraint = constraintDeclaration ? getTypeFromTypeNode(constraintDeclaration) : noConstraintOrDefaultType;
typeParameter.constraint = constraintDeclaration ? getTypeFromTypeNode(constraintDeclaration) : noConstraintType;
}
}
return typeParameter.constraint === noConstraintOrDefaultType ? undefined : typeParameter.constraint;
return typeParameter.constraint === noConstraintType ? undefined : typeParameter.constraint;
}

function getParentSymbolOfTypeParameter(typeParameter: TypeParameter): Symbol {
Expand Down Expand Up @@ -15846,12 +15846,12 @@ namespace ts {
}
}

/**
/**
* Static members being set on a constructor function may conflict with built-in properties
* of Function. Esp. in ECMAScript 5 there are non-configurable and non-writable
* built-in properties. This check issues a transpile error when a class has a static
* of Function. Esp. in ECMAScript 5 there are non-configurable and non-writable
* built-in properties. This check issues a transpile error when a class has a static
* member with the same name as a non-writable built-in property.
*
*
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.3
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.5
* @see http://www.ecma-international.org/ecma-262/6.0/#sec-properties-of-the-function-constructor
Expand Down