mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Optional variance annotations (#48240)
* Simplify getVariancesWorker and associated logic * Accept new API baselines * Add 'in' and 'out' modififers / add modifiers to type parameters * Check variance annotations * Update test runner * Accept new API baselines * Allow variance annotations only on certain type parameters * Add deprecated implementation of createTypeParameterDeclaration * Accept new API baselines * Report variance markers as 'sub-XXX' and 'super-XXX' * Add tests * Accept new baselines
This commit is contained in:
+112
-61
@@ -347,6 +347,7 @@ namespace ts {
|
||||
let instantiationDepth = 0;
|
||||
let inlineLevel = 0;
|
||||
let currentNode: Node | undefined;
|
||||
let varianceTypeParameter: TypeParameter | undefined;
|
||||
|
||||
const emptySymbols = createSymbolTable();
|
||||
const arrayVariances = [VarianceFlags.Covariant];
|
||||
@@ -761,6 +762,7 @@ namespace ts {
|
||||
const subtypeReductionCache = new Map<string, Type[]>();
|
||||
const evolvingArrayTypes: EvolvingArrayType[] = [];
|
||||
const undefinedProperties: SymbolTable = new Map();
|
||||
const markerTypes = new Set<number>();
|
||||
|
||||
const unknownSymbol = createSymbol(SymbolFlags.Property, "unknown" as __String);
|
||||
const resolvingSymbol = createSymbol(0, InternalSymbolName.Resolving);
|
||||
@@ -4985,9 +4987,12 @@ namespace ts {
|
||||
return factory.createTypeReferenceNode(factory.createIdentifier(idText(name)), /*typeArguments*/ undefined);
|
||||
}
|
||||
// Ignore constraint/default when creating a usage (as opposed to declaration) of a type parameter.
|
||||
return type.symbol
|
||||
? symbolToTypeNode(type.symbol, context, SymbolFlags.Type)
|
||||
: factory.createTypeReferenceNode(factory.createIdentifier("?"), /*typeArguments*/ undefined);
|
||||
if (type.symbol) {
|
||||
return symbolToTypeNode(type.symbol, context, SymbolFlags.Type);
|
||||
}
|
||||
const name = (type === markerSuperType || type === markerSubType) && varianceTypeParameter && varianceTypeParameter.symbol ?
|
||||
(type === markerSubType ? "sub-" : "super-") + symbolName(varianceTypeParameter.symbol) : "?";
|
||||
return factory.createTypeReferenceNode(factory.createIdentifier(name), /*typeArguments*/ undefined);
|
||||
}
|
||||
if (type.flags & TypeFlags.Union && (type as UnionType).origin) {
|
||||
type = (type as UnionType).origin!;
|
||||
@@ -5107,7 +5112,7 @@ namespace ts {
|
||||
// type stays homomorphic
|
||||
return factory.createConditionalTypeNode(
|
||||
typeToTypeNodeHelper(getModifiersTypeFromMappedType(type), context),
|
||||
factory.createInferTypeNode(factory.createTypeParameterDeclaration(factory.cloneNode(newTypeVariable!.typeName) as Identifier)),
|
||||
factory.createInferTypeNode(factory.createTypeParameterDeclaration(/*modifiers*/ undefined, factory.cloneNode(newTypeVariable!.typeName) as Identifier)),
|
||||
result,
|
||||
factory.createKeywordTypeNode(SyntaxKind.NeverKeyword)
|
||||
);
|
||||
@@ -5795,11 +5800,12 @@ namespace ts {
|
||||
function typeParameterToDeclarationWithConstraint(type: TypeParameter, context: NodeBuilderContext, constraintNode: TypeNode | undefined): TypeParameterDeclaration {
|
||||
const savedContextFlags = context.flags;
|
||||
context.flags &= ~NodeBuilderFlags.WriteTypeParametersInQualifiedName; // Avoids potential infinite loop when building for a claimspace with a generic
|
||||
const modifiers = factory.createModifiersFromModifierFlags(getVarianceModifiers(type));
|
||||
const name = typeParameterToName(type, context);
|
||||
const defaultParameter = getDefaultFromTypeParameter(type);
|
||||
const defaultParameterNode = defaultParameter && typeToTypeNodeHelper(defaultParameter, context);
|
||||
context.flags = savedContextFlags;
|
||||
return factory.createTypeParameterDeclaration(name, constraintNode, defaultParameterNode);
|
||||
return factory.createTypeParameterDeclaration(modifiers, name, constraintNode, defaultParameterNode);
|
||||
}
|
||||
|
||||
function typeParameterToDeclaration(type: TypeParameter, context: NodeBuilderContext, constraint = getConstraintOfTypeParameter(type)): TypeParameterDeclaration {
|
||||
@@ -18404,7 +18410,7 @@ namespace ts {
|
||||
generalizedSourceType = getTypeNameForErrorDisplay(generalizedSource);
|
||||
}
|
||||
|
||||
if (target.flags & TypeFlags.TypeParameter) {
|
||||
if (target.flags & TypeFlags.TypeParameter && target !== markerSuperType && target !== markerSubType) {
|
||||
const constraint = getBaseConstraintOfType(target);
|
||||
let needsOriginalSource;
|
||||
if (constraint && (isTypeAssignableTo(generalizedSource, constraint) || (needsOriginalSource = isTypeAssignableTo(source, constraint)))) {
|
||||
@@ -19227,9 +19233,8 @@ namespace ts {
|
||||
// We limit alias variance probing to only object and conditional types since their alias behavior
|
||||
// is more predictable than other, interned types, which may or may not have an alias depending on
|
||||
// the order in which things were checked.
|
||||
if (sourceFlags & (TypeFlags.Object | TypeFlags.Conditional) && source.aliasSymbol &&
|
||||
source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
|
||||
!(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
|
||||
if (sourceFlags & (TypeFlags.Object | TypeFlags.Conditional) && source.aliasSymbol && source.aliasTypeArguments &&
|
||||
source.aliasSymbol === target.aliasSymbol && !(isMarkerType(source) || isMarkerType(target))) {
|
||||
const variances = getAliasVariances(source.aliasSymbol);
|
||||
if (variances === emptyArray) {
|
||||
return Ternary.Unknown;
|
||||
@@ -19608,7 +19613,7 @@ namespace ts {
|
||||
return Ternary.False;
|
||||
}
|
||||
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (source as TypeReference).target === (target as TypeReference).target &&
|
||||
!isTupleType(source) && !(getObjectFlags(source) & ObjectFlags.MarkerType || getObjectFlags(target) & ObjectFlags.MarkerType)) {
|
||||
!isTupleType(source) && !(isMarkerType(source) || isMarkerType(target))) {
|
||||
// When strictNullChecks is disabled, the element type of the empty array literal is undefinedWideningType,
|
||||
// and an empty array literal wouldn't be assignable to a `never[]` without this check.
|
||||
if (isEmptyArrayLiteralType(source)) {
|
||||
@@ -20559,21 +20564,15 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return a type reference where the source type parameter is replaced with the target marker
|
||||
// type, and flag the result as a marker type reference.
|
||||
function getMarkerTypeReference(type: GenericType, source: TypeParameter, target: Type) {
|
||||
const result = createTypeReference(type, map(type.typeParameters, t => t === source ? target : t));
|
||||
result.objectFlags |= ObjectFlags.MarkerType;
|
||||
return result;
|
||||
function getVariances(type: GenericType): VarianceFlags[] {
|
||||
// Arrays and tuples are known to be covariant, no need to spend time computing this.
|
||||
return type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple ?
|
||||
arrayVariances :
|
||||
getVariancesWorker(type.symbol, type.typeParameters);
|
||||
}
|
||||
|
||||
function getAliasVariances(symbol: Symbol) {
|
||||
const links = getSymbolLinks(symbol);
|
||||
return getVariancesWorker(links.typeParameters, links, (_links, param, marker) => {
|
||||
const type = getTypeAliasInstantiation(symbol, instantiateTypes(links.typeParameters!, makeUnaryTypeMapper(param, marker)));
|
||||
type.aliasTypeArgumentsContainsMarker = true;
|
||||
return type;
|
||||
});
|
||||
return getVariancesWorker(symbol, getSymbolLinks(symbol).typeParameters);
|
||||
}
|
||||
|
||||
// Return an array containing the variance of each type parameter. The variance is effectively
|
||||
@@ -20581,55 +20580,71 @@ namespace ts {
|
||||
// generic type are structurally compared. We infer the variance information by comparing
|
||||
// instantiations of the generic type for type arguments with known relations. The function
|
||||
// returns the emptyArray singleton when invoked recursively for the given generic type.
|
||||
function getVariancesWorker<TCache extends { variances?: VarianceFlags[] }>(typeParameters: readonly TypeParameter[] = emptyArray, cache: TCache, createMarkerType: (input: TCache, param: TypeParameter, marker: Type) => Type): VarianceFlags[] {
|
||||
let variances = cache.variances;
|
||||
if (!variances) {
|
||||
tracing?.push(tracing.Phase.CheckTypes, "getVariancesWorker", { arity: typeParameters.length, id: (cache as any).id ?? (cache as any).declaredType?.id ?? -1 });
|
||||
// The emptyArray singleton is used to signal a recursive invocation.
|
||||
cache.variances = emptyArray;
|
||||
variances = [];
|
||||
function getVariancesWorker(symbol: Symbol, typeParameters: readonly TypeParameter[] = emptyArray): VarianceFlags[] {
|
||||
const links = getSymbolLinks(symbol);
|
||||
if (!links.variances) {
|
||||
tracing?.push(tracing.Phase.CheckTypes, "getVariancesWorker", { arity: typeParameters.length, id: getTypeId(getDeclaredTypeOfSymbol(symbol)) });
|
||||
links.variances = emptyArray;
|
||||
const variances = [];
|
||||
for (const tp of typeParameters) {
|
||||
let unmeasurable = false;
|
||||
let unreliable = false;
|
||||
const oldHandler = outofbandVarianceMarkerHandler;
|
||||
outofbandVarianceMarkerHandler = (onlyUnreliable) => onlyUnreliable ? unreliable = true : unmeasurable = true;
|
||||
// We first compare instantiations where the type parameter is replaced with
|
||||
// marker types that have a known subtype relationship. From this we can infer
|
||||
// invariance, covariance, contravariance or bivariance.
|
||||
const typeWithSuper = createMarkerType(cache, tp, markerSuperType);
|
||||
const typeWithSub = createMarkerType(cache, tp, markerSubType);
|
||||
let variance = (isTypeAssignableTo(typeWithSub, typeWithSuper) ? VarianceFlags.Covariant : 0) |
|
||||
(isTypeAssignableTo(typeWithSuper, typeWithSub) ? VarianceFlags.Contravariant : 0);
|
||||
// If the instantiations appear to be related bivariantly it may be because the
|
||||
// type parameter is independent (i.e. it isn't witnessed anywhere in the generic
|
||||
// type). To determine this we compare instantiations where the type parameter is
|
||||
// replaced with marker types that are known to be unrelated.
|
||||
if (variance === VarianceFlags.Bivariant && isTypeAssignableTo(createMarkerType(cache, tp, markerOtherType), typeWithSuper)) {
|
||||
variance = VarianceFlags.Independent;
|
||||
}
|
||||
outofbandVarianceMarkerHandler = oldHandler;
|
||||
if (unmeasurable || unreliable) {
|
||||
if (unmeasurable) {
|
||||
variance |= VarianceFlags.Unmeasurable;
|
||||
const modifiers = getVarianceModifiers(tp);
|
||||
let variance = modifiers & ModifierFlags.Out ?
|
||||
modifiers & ModifierFlags.In ? VarianceFlags.Invariant : VarianceFlags.Covariant :
|
||||
modifiers & ModifierFlags.In ? VarianceFlags.Contravariant : undefined;
|
||||
if (variance === undefined) {
|
||||
let unmeasurable = false;
|
||||
let unreliable = false;
|
||||
const oldHandler = outofbandVarianceMarkerHandler;
|
||||
outofbandVarianceMarkerHandler = (onlyUnreliable) => onlyUnreliable ? unreliable = true : unmeasurable = true;
|
||||
// We first compare instantiations where the type parameter is replaced with
|
||||
// marker types that have a known subtype relationship. From this we can infer
|
||||
// invariance, covariance, contravariance or bivariance.
|
||||
const typeWithSuper = createMarkerType(symbol, tp, markerSuperType);
|
||||
const typeWithSub = createMarkerType(symbol, tp, markerSubType);
|
||||
variance = (isTypeAssignableTo(typeWithSub, typeWithSuper) ? VarianceFlags.Covariant : 0) |
|
||||
(isTypeAssignableTo(typeWithSuper, typeWithSub) ? VarianceFlags.Contravariant : 0);
|
||||
// If the instantiations appear to be related bivariantly it may be because the
|
||||
// type parameter is independent (i.e. it isn't witnessed anywhere in the generic
|
||||
// type). To determine this we compare instantiations where the type parameter is
|
||||
// replaced with marker types that are known to be unrelated.
|
||||
if (variance === VarianceFlags.Bivariant && isTypeAssignableTo(createMarkerType(symbol, tp, markerOtherType), typeWithSuper)) {
|
||||
variance = VarianceFlags.Independent;
|
||||
}
|
||||
if (unreliable) {
|
||||
variance |= VarianceFlags.Unreliable;
|
||||
outofbandVarianceMarkerHandler = oldHandler;
|
||||
if (unmeasurable || unreliable) {
|
||||
if (unmeasurable) {
|
||||
variance |= VarianceFlags.Unmeasurable;
|
||||
}
|
||||
if (unreliable) {
|
||||
variance |= VarianceFlags.Unreliable;
|
||||
}
|
||||
}
|
||||
}
|
||||
variances.push(variance);
|
||||
}
|
||||
cache.variances = variances;
|
||||
links.variances = variances;
|
||||
tracing?.pop();
|
||||
}
|
||||
return variances;
|
||||
return links.variances;
|
||||
}
|
||||
|
||||
function getVariances(type: GenericType): VarianceFlags[] {
|
||||
// Arrays and tuples are known to be covariant, no need to spend time computing this.
|
||||
if (type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
|
||||
return arrayVariances;
|
||||
}
|
||||
return getVariancesWorker(type.typeParameters, type, getMarkerTypeReference);
|
||||
function createMarkerType(symbol: Symbol, source: TypeParameter, target: Type) {
|
||||
const mapper = makeUnaryTypeMapper(source, target);
|
||||
const type = getDeclaredTypeOfSymbol(symbol);
|
||||
const result = symbol.flags & SymbolFlags.TypeAlias ?
|
||||
getTypeAliasInstantiation(symbol, instantiateTypes(getSymbolLinks(symbol).typeParameters!, mapper)) :
|
||||
createTypeReference(type as GenericType, instantiateTypes((type as GenericType).typeParameters, mapper));
|
||||
markerTypes.add(getTypeId(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
function isMarkerType(type: Type) {
|
||||
return markerTypes.has(getTypeId(type));
|
||||
}
|
||||
|
||||
function getVarianceModifiers(tp: TypeParameter): ModifierFlags {
|
||||
return (some(tp.symbol?.declarations, d => hasSyntacticModifier(d, ModifierFlags.In)) ? ModifierFlags.In : 0) |
|
||||
(some(tp.symbol?.declarations, d => hasSyntacticModifier(d, ModifierFlags.Out)) ? ModifierFlags.Out: 0);
|
||||
}
|
||||
|
||||
// Return true if the given type reference has a 'void' type argument for a covariant type parameter.
|
||||
@@ -34670,6 +34685,7 @@ namespace ts {
|
||||
|
||||
function checkTypeParameter(node: TypeParameterDeclaration) {
|
||||
// Grammar Checking
|
||||
checkGrammarModifiers(node);
|
||||
if (node.expression) {
|
||||
grammarErrorOnFirstToken(node.expression, Diagnostics.Type_expected);
|
||||
}
|
||||
@@ -34687,6 +34703,18 @@ namespace ts {
|
||||
if (constraintType && defaultType) {
|
||||
checkTypeAssignableTo(defaultType, getTypeWithThisArgument(instantiateType(constraintType, makeUnaryTypeMapper(typeParameter, defaultType)), defaultType), node.default, Diagnostics.Type_0_does_not_satisfy_the_constraint_1);
|
||||
}
|
||||
if (node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.ClassDeclaration || node.parent.kind === SyntaxKind.TypeAliasDeclaration) {
|
||||
const modifiers = getVarianceModifiers(typeParameter);
|
||||
if (modifiers === ModifierFlags.In || modifiers === ModifierFlags.Out) {
|
||||
const symbol = getSymbolOfNode(node.parent);
|
||||
const source = createMarkerType(symbol, typeParameter, modifiers === ModifierFlags.Out ? markerSubType : markerSuperType);
|
||||
const target = createMarkerType(symbol, typeParameter, modifiers === ModifierFlags.Out ? markerSuperType : markerSubType);
|
||||
const saveVarianceTypeParameter = typeParameter;
|
||||
varianceTypeParameter = typeParameter;
|
||||
checkTypeAssignableTo(source, target, node, Diagnostics.Type_0_is_not_assignable_to_type_1_as_implied_by_variance_annotation);
|
||||
varianceTypeParameter = saveVarianceTypeParameter;
|
||||
}
|
||||
}
|
||||
if (produceDiagnostics) {
|
||||
checkTypeNameIsReserved(node.name, Diagnostics.Type_parameter_name_cannot_be_0);
|
||||
}
|
||||
@@ -43098,6 +43126,11 @@ namespace ts {
|
||||
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_an_index_signature, tokenToString(modifier.kind));
|
||||
}
|
||||
}
|
||||
if (modifier.kind !== SyntaxKind.InKeyword && modifier.kind !== SyntaxKind.OutKeyword) {
|
||||
if (node.kind === SyntaxKind.TypeParameter) {
|
||||
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_type_parameter, tokenToString(modifier.kind));
|
||||
}
|
||||
}
|
||||
switch (modifier.kind) {
|
||||
case SyntaxKind.ConstKeyword:
|
||||
if (node.kind !== SyntaxKind.EnumDeclaration) {
|
||||
@@ -43305,6 +43338,23 @@ namespace ts {
|
||||
flags |= ModifierFlags.Async;
|
||||
lastAsync = modifier;
|
||||
break;
|
||||
|
||||
case SyntaxKind.InKeyword:
|
||||
case SyntaxKind.OutKeyword:
|
||||
const inOutFlag = modifier.kind === SyntaxKind.InKeyword ? ModifierFlags.In : ModifierFlags.Out;
|
||||
const inOutText = modifier.kind === SyntaxKind.InKeyword ? "in" : "out";
|
||||
if (node.kind !== SyntaxKind.TypeParameter || (node.parent.kind !== SyntaxKind.InterfaceDeclaration &&
|
||||
node.parent.kind !== SyntaxKind.ClassDeclaration && node.parent.kind !== SyntaxKind.TypeAliasDeclaration)) {
|
||||
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_can_only_appear_on_a_type_parameter_of_a_class_interface_or_type_alias, inOutText);
|
||||
}
|
||||
if (flags & inOutFlag) {
|
||||
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, inOutText);
|
||||
}
|
||||
if (inOutFlag & ModifierFlags.In && flags & ModifierFlags.Out) {
|
||||
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "in", "out");
|
||||
}
|
||||
flags |= inOutFlag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43364,6 +43414,7 @@ namespace ts {
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.TypeParameter:
|
||||
return false;
|
||||
default:
|
||||
if (node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) {
|
||||
|
||||
@@ -883,6 +883,14 @@
|
||||
"category": "Error",
|
||||
"code": 1272
|
||||
},
|
||||
"'{0}' modifier cannot appear on a type parameter": {
|
||||
"category": "Error",
|
||||
"code": 1273
|
||||
},
|
||||
"'{0}' modifier can only appear on a type parameter of a class, interface or type alias": {
|
||||
"category": "Error",
|
||||
"code": 1274
|
||||
},
|
||||
|
||||
"'with' statements are not allowed in an async function block.": {
|
||||
"category": "Error",
|
||||
@@ -2727,6 +2735,10 @@
|
||||
"category": "Error",
|
||||
"code": 2635
|
||||
},
|
||||
"Type '{0}' is not assignable to type '{1}' as implied by variance annotation.": {
|
||||
"category": "Error",
|
||||
"code": 2636
|
||||
},
|
||||
|
||||
"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {
|
||||
"category": "Error",
|
||||
|
||||
@@ -2009,6 +2009,7 @@ namespace ts {
|
||||
//
|
||||
|
||||
function emitTypeParameter(node: TypeParameterDeclaration) {
|
||||
emitModifiers(node, node.modifiers);
|
||||
emit(node.name);
|
||||
if (node.constraint) {
|
||||
writeSpace();
|
||||
|
||||
@@ -998,6 +998,8 @@ namespace ts {
|
||||
case SyntaxKind.BigIntKeyword:
|
||||
case SyntaxKind.NeverKeyword:
|
||||
case SyntaxKind.ObjectKeyword:
|
||||
case SyntaxKind.InKeyword:
|
||||
case SyntaxKind.OutKeyword:
|
||||
case SyntaxKind.OverrideKeyword:
|
||||
case SyntaxKind.StringKeyword:
|
||||
case SyntaxKind.BooleanKeyword:
|
||||
@@ -1077,6 +1079,8 @@ namespace ts {
|
||||
if (flags & ModifierFlags.Override) result.push(createModifier(SyntaxKind.OverrideKeyword));
|
||||
if (flags & ModifierFlags.Readonly) result.push(createModifier(SyntaxKind.ReadonlyKeyword));
|
||||
if (flags & ModifierFlags.Async) result.push(createModifier(SyntaxKind.AsyncKeyword));
|
||||
if (flags & ModifierFlags.In) result.push(createModifier(SyntaxKind.InKeyword));
|
||||
if (flags & ModifierFlags.Out) result.push(createModifier(SyntaxKind.OutKeyword));
|
||||
return result.length ? result : undefined;
|
||||
}
|
||||
|
||||
@@ -1126,11 +1130,27 @@ namespace ts {
|
||||
//
|
||||
|
||||
// @api
|
||||
function createTypeParameterDeclaration(name: string | Identifier, constraint?: TypeNode, defaultType?: TypeNode) {
|
||||
function createTypeParameterDeclaration(modifiers: readonly Modifier[] | undefined, name: string | Identifier, constraint?: TypeNode, defaultType?: TypeNode): TypeParameterDeclaration;
|
||||
/** @deprecated */
|
||||
function createTypeParameterDeclaration(name: string | Identifier, constraint?: TypeNode, defaultType?: TypeNode): TypeParameterDeclaration;
|
||||
function createTypeParameterDeclaration(modifiersOrName: readonly Modifier[] | string | Identifier | undefined , nameOrConstraint?: string | Identifier | TypeNode, constraintOrDefault?: TypeNode, defaultType?: TypeNode) {
|
||||
let name;
|
||||
let modifiers;
|
||||
let constraint;
|
||||
if (modifiersOrName === undefined || isArray(modifiersOrName)) {
|
||||
modifiers = modifiersOrName;
|
||||
name = nameOrConstraint as string | Identifier;
|
||||
constraint = constraintOrDefault;
|
||||
}
|
||||
else {
|
||||
modifiers = undefined;
|
||||
name = modifiersOrName;
|
||||
constraint = nameOrConstraint as TypeNode | undefined;
|
||||
}
|
||||
const node = createBaseNamedDeclaration<TypeParameterDeclaration>(
|
||||
SyntaxKind.TypeParameter,
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
modifiers,
|
||||
name
|
||||
);
|
||||
node.constraint = constraint;
|
||||
@@ -1140,11 +1160,28 @@ namespace ts {
|
||||
}
|
||||
|
||||
// @api
|
||||
function updateTypeParameterDeclaration(node: TypeParameterDeclaration, name: Identifier, constraint: TypeNode | undefined, defaultType: TypeNode | undefined) {
|
||||
return node.name !== name
|
||||
function updateTypeParameterDeclaration(node: TypeParameterDeclaration, modifiers: readonly Modifier[] | undefined, name: Identifier, constraint: TypeNode | undefined, defaultType: TypeNode | undefined): TypeParameterDeclaration;
|
||||
/** @deprecated */
|
||||
function updateTypeParameterDeclaration(node: TypeParameterDeclaration, name: Identifier, constraint: TypeNode | undefined, defaultType: TypeNode | undefined): TypeParameterDeclaration;
|
||||
function updateTypeParameterDeclaration(node: TypeParameterDeclaration, modifiersOrName: readonly Modifier[] | Identifier | undefined, nameOrConstraint: Identifier | TypeNode | undefined, constraintOrDefault: TypeNode | undefined, defaultType?: TypeNode | undefined) {
|
||||
let name;
|
||||
let modifiers;
|
||||
let constraint;
|
||||
if (modifiersOrName === undefined || isArray(modifiersOrName)) {
|
||||
modifiers = modifiersOrName;
|
||||
name = nameOrConstraint as Identifier;
|
||||
constraint = constraintOrDefault;
|
||||
}
|
||||
else {
|
||||
modifiers = undefined;
|
||||
name = modifiersOrName;
|
||||
constraint = nameOrConstraint as TypeNode | undefined;
|
||||
}
|
||||
return node.modifiers !== modifiers
|
||||
|| node.name !== name
|
||||
|| node.constraint !== constraint
|
||||
|| node.default !== defaultType
|
||||
? update(createTypeParameterDeclaration(name, constraint, defaultType), node)
|
||||
? update(createTypeParameterDeclaration(modifiers, name, constraint, defaultType), node)
|
||||
: node;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,8 @@ namespace ts {
|
||||
return visitNode(cbNode, (node as QualifiedName).left) ||
|
||||
visitNode(cbNode, (node as QualifiedName).right);
|
||||
case SyntaxKind.TypeParameter:
|
||||
return visitNode(cbNode, (node as TypeParameterDeclaration).name) ||
|
||||
return visitNodes(cbNode, cbNodes, node.modifiers) ||
|
||||
visitNode(cbNode, (node as TypeParameterDeclaration).name) ||
|
||||
visitNode(cbNode, (node as TypeParameterDeclaration).constraint) ||
|
||||
visitNode(cbNode, (node as TypeParameterDeclaration).default) ||
|
||||
visitNode(cbNode, (node as TypeParameterDeclaration).expression);
|
||||
@@ -2176,7 +2177,7 @@ namespace ts {
|
||||
case ParsingContext.ArrayBindingElements:
|
||||
return token() === SyntaxKind.CommaToken || token() === SyntaxKind.DotDotDotToken || isBindingIdentifierOrPrivateIdentifierOrPattern();
|
||||
case ParsingContext.TypeParameters:
|
||||
return isIdentifier();
|
||||
return token() === SyntaxKind.InKeyword || isIdentifier();
|
||||
case ParsingContext.ArrayLiteralMembers:
|
||||
switch (token()) {
|
||||
case SyntaxKind.CommaToken:
|
||||
@@ -3176,6 +3177,7 @@ namespace ts {
|
||||
|
||||
function parseTypeParameter(): TypeParameterDeclaration {
|
||||
const pos = getNodePos();
|
||||
const modifiers = parseModifiers();
|
||||
const name = parseIdentifier();
|
||||
let constraint: TypeNode | undefined;
|
||||
let expression: Expression | undefined;
|
||||
@@ -3200,7 +3202,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const defaultType = parseOptional(SyntaxKind.EqualsToken) ? parseType() : undefined;
|
||||
const node = factory.createTypeParameterDeclaration(name, constraint, defaultType);
|
||||
const node = factory.createTypeParameterDeclaration(modifiers, name, constraint, defaultType);
|
||||
node.expression = expression;
|
||||
return finishNode(node, pos);
|
||||
}
|
||||
@@ -3605,7 +3607,7 @@ namespace ts {
|
||||
const name = parseIdentifierName();
|
||||
parseExpected(SyntaxKind.InKeyword);
|
||||
const type = parseType();
|
||||
return finishNode(factory.createTypeParameterDeclaration(name, type, /*defaultType*/ undefined), pos);
|
||||
return finishNode(factory.createTypeParameterDeclaration(/*modifiers*/ undefined, name, type, /*defaultType*/ undefined), pos);
|
||||
}
|
||||
|
||||
function parseMappedType() {
|
||||
@@ -3961,6 +3963,7 @@ namespace ts {
|
||||
const pos = getNodePos();
|
||||
return finishNode(
|
||||
factory.createTypeParameterDeclaration(
|
||||
/*modifiers*/ undefined,
|
||||
parseIdentifier(),
|
||||
/*constraint*/ undefined,
|
||||
/*defaultType*/ undefined
|
||||
@@ -8656,7 +8659,7 @@ namespace ts {
|
||||
if (nodeIsMissing(name)) {
|
||||
return undefined;
|
||||
}
|
||||
return finishNode(factory.createTypeParameterDeclaration(name, /*constraint*/ undefined, defaultType), typeParameterPos);
|
||||
return finishNode(factory.createTypeParameterDeclaration(/*modifiers*/ undefined, name, /*constraint*/ undefined, defaultType), typeParameterPos);
|
||||
}
|
||||
|
||||
function parseTemplateTagTypeParameters() {
|
||||
|
||||
@@ -2414,6 +2414,8 @@ namespace ts {
|
||||
case SyntaxKind.DeclareKeyword:
|
||||
case SyntaxKind.AbstractKeyword:
|
||||
case SyntaxKind.OverrideKeyword:
|
||||
case SyntaxKind.InKeyword:
|
||||
case SyntaxKind.OutKeyword:
|
||||
diagnostics.push(createDiagnosticForNode(modifier, Diagnostics.The_0_modifier_can_only_be_used_in_TypeScript_files, tokenToString(modifier.kind)));
|
||||
break;
|
||||
|
||||
|
||||
@@ -131,6 +131,7 @@ namespace ts {
|
||||
protected: SyntaxKind.ProtectedKeyword,
|
||||
public: SyntaxKind.PublicKeyword,
|
||||
override: SyntaxKind.OverrideKeyword,
|
||||
out: SyntaxKind.OutKeyword,
|
||||
readonly: SyntaxKind.ReadonlyKeyword,
|
||||
require: SyntaxKind.RequireKeyword,
|
||||
global: SyntaxKind.GlobalKeyword,
|
||||
|
||||
@@ -1029,7 +1029,7 @@ namespace ts {
|
||||
}
|
||||
case SyntaxKind.TypeParameter: {
|
||||
if (isPrivateMethodTypeParameter(input) && (input.default || input.constraint)) {
|
||||
return cleanup(factory.updateTypeParameterDeclaration(input, input.name, /*constraint*/ undefined, /*defaultType*/ undefined));
|
||||
return cleanup(factory.updateTypeParameterDeclaration(input, input.modifiers, input.name, /*constraint*/ undefined, /*defaultType*/ undefined));
|
||||
}
|
||||
return cleanup(visitEachChild(input, visitDeclarationSubtree, context));
|
||||
}
|
||||
|
||||
@@ -373,6 +373,8 @@ namespace ts {
|
||||
case SyntaxKind.ConstKeyword:
|
||||
case SyntaxKind.DeclareKeyword:
|
||||
case SyntaxKind.ReadonlyKeyword:
|
||||
case SyntaxKind.InKeyword:
|
||||
case SyntaxKind.OutKeyword:
|
||||
// TypeScript accessibility and readonly modifiers are elided
|
||||
// falls through
|
||||
case SyntaxKind.ArrayType:
|
||||
|
||||
+37
-25
@@ -176,6 +176,7 @@ namespace ts {
|
||||
ModuleKeyword,
|
||||
NamespaceKeyword,
|
||||
NeverKeyword,
|
||||
OutKeyword,
|
||||
ReadonlyKeyword,
|
||||
RequireKeyword,
|
||||
NumberKeyword,
|
||||
@@ -602,6 +603,7 @@ namespace ts {
|
||||
| SyntaxKind.ProtectedKeyword
|
||||
| SyntaxKind.PublicKeyword
|
||||
| SyntaxKind.ReadonlyKeyword
|
||||
| SyntaxKind.OutKeyword
|
||||
| SyntaxKind.OverrideKeyword
|
||||
| SyntaxKind.RequireKeyword
|
||||
| SyntaxKind.ReturnKeyword
|
||||
@@ -634,10 +636,12 @@ namespace ts {
|
||||
| SyntaxKind.DeclareKeyword
|
||||
| SyntaxKind.DefaultKeyword
|
||||
| SyntaxKind.ExportKeyword
|
||||
| SyntaxKind.InKeyword
|
||||
| SyntaxKind.PrivateKeyword
|
||||
| SyntaxKind.ProtectedKeyword
|
||||
| SyntaxKind.PublicKeyword
|
||||
| SyntaxKind.ReadonlyKeyword
|
||||
| SyntaxKind.OutKeyword
|
||||
| SyntaxKind.OverrideKeyword
|
||||
| SyntaxKind.StaticKeyword
|
||||
;
|
||||
@@ -817,6 +821,8 @@ namespace ts {
|
||||
|
||||
Deprecated = 1 << 13, // Deprecated tag.
|
||||
Override = 1 << 14, // Override method.
|
||||
In = 1 << 15, // Contravariance modifier
|
||||
Out = 1 << 16, // Covariance modifier
|
||||
HasComputedFlags = 1 << 29, // Modifier flags have been computed
|
||||
|
||||
AccessibilityModifier = Public | Private | Protected,
|
||||
@@ -824,9 +830,9 @@ namespace ts {
|
||||
ParameterPropertyModifier = AccessibilityModifier | Readonly | Override,
|
||||
NonPublicAccessibilityModifier = Private | Protected,
|
||||
|
||||
TypeScriptModifier = Ambient | Public | Private | Protected | Readonly | Abstract | Const | Override,
|
||||
TypeScriptModifier = Ambient | Public | Private | Protected | Readonly | Abstract | Const | Override | In | Out,
|
||||
ExportDefault = Export | Default,
|
||||
All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Async | Default | Const | Deprecated | Override
|
||||
All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Async | Default | Const | Deprecated | Override | In | Out
|
||||
}
|
||||
|
||||
export const enum JsxFlags {
|
||||
@@ -1066,10 +1072,12 @@ namespace ts {
|
||||
export type DeclareKeyword = ModifierToken<SyntaxKind.DeclareKeyword>;
|
||||
export type DefaultKeyword = ModifierToken<SyntaxKind.DefaultKeyword>;
|
||||
export type ExportKeyword = ModifierToken<SyntaxKind.ExportKeyword>;
|
||||
export type InKeyword = ModifierToken<SyntaxKind.InKeyword>;
|
||||
export type PrivateKeyword = ModifierToken<SyntaxKind.PrivateKeyword>;
|
||||
export type ProtectedKeyword = ModifierToken<SyntaxKind.ProtectedKeyword>;
|
||||
export type PublicKeyword = ModifierToken<SyntaxKind.PublicKeyword>;
|
||||
export type ReadonlyKeyword = ModifierToken<SyntaxKind.ReadonlyKeyword>;
|
||||
export type OutKeyword = ModifierToken<SyntaxKind.OutKeyword>;
|
||||
export type OverrideKeyword = ModifierToken<SyntaxKind.OverrideKeyword>;
|
||||
export type StaticKeyword = ModifierToken<SyntaxKind.StaticKeyword>;
|
||||
|
||||
@@ -1083,9 +1091,11 @@ namespace ts {
|
||||
| DeclareKeyword
|
||||
| DefaultKeyword
|
||||
| ExportKeyword
|
||||
| InKeyword
|
||||
| PrivateKeyword
|
||||
| ProtectedKeyword
|
||||
| PublicKeyword
|
||||
| OutKeyword
|
||||
| OverrideKeyword
|
||||
| ReadonlyKeyword
|
||||
| StaticKeyword
|
||||
@@ -5244,7 +5254,6 @@ namespace ts {
|
||||
pattern?: DestructuringPattern; // Destructuring pattern represented by type (if any)
|
||||
aliasSymbol?: Symbol; // Alias associated with type
|
||||
aliasTypeArguments?: readonly Type[]; // Alias type arguments (if any)
|
||||
/* @internal */ aliasTypeArgumentsContainsMarker?: boolean; // Alias type arguments (if any)
|
||||
/* @internal */
|
||||
permissiveInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type
|
||||
/* @internal */
|
||||
@@ -5325,22 +5334,21 @@ namespace ts {
|
||||
ObjectLiteralPatternWithComputedProperties = 1 << 9, // Object literal pattern with computed properties
|
||||
ReverseMapped = 1 << 10, // Object contains a property from a reverse-mapped type
|
||||
JsxAttributes = 1 << 11, // Jsx attributes type
|
||||
MarkerType = 1 << 12, // Marker type used for variance probing
|
||||
JSLiteral = 1 << 13, // Object type declared in JS - disables errors on read/write of nonexisting members
|
||||
FreshLiteral = 1 << 14, // Fresh object literal
|
||||
ArrayLiteral = 1 << 15, // Originates in an array literal
|
||||
JSLiteral = 1 << 12, // Object type declared in JS - disables errors on read/write of nonexisting members
|
||||
FreshLiteral = 1 << 13, // Fresh object literal
|
||||
ArrayLiteral = 1 << 14, // Originates in an array literal
|
||||
/* @internal */
|
||||
PrimitiveUnion = 1 << 16, // Union of only primitive types
|
||||
PrimitiveUnion = 1 << 15, // Union of only primitive types
|
||||
/* @internal */
|
||||
ContainsWideningType = 1 << 17, // Type is or contains undefined or null widening type
|
||||
ContainsWideningType = 1 << 16, // Type is or contains undefined or null widening type
|
||||
/* @internal */
|
||||
ContainsObjectOrArrayLiteral = 1 << 18, // Type is or contains object literal type
|
||||
ContainsObjectOrArrayLiteral = 1 << 17, // Type is or contains object literal type
|
||||
/* @internal */
|
||||
NonInferrableType = 1 << 19, // Type is or contains anyFunctionType or silentNeverType
|
||||
NonInferrableType = 1 << 18, // Type is or contains anyFunctionType or silentNeverType
|
||||
/* @internal */
|
||||
CouldContainTypeVariablesComputed = 1 << 20, // CouldContainTypeVariables flag has been computed
|
||||
CouldContainTypeVariablesComputed = 1 << 19, // CouldContainTypeVariables flag has been computed
|
||||
/* @internal */
|
||||
CouldContainTypeVariables = 1 << 21, // Type could contain a type variable
|
||||
CouldContainTypeVariables = 1 << 20, // Type could contain a type variable
|
||||
|
||||
ClassOrInterface = Class | Interface,
|
||||
/* @internal */
|
||||
@@ -5352,36 +5360,36 @@ namespace ts {
|
||||
ObjectTypeKindMask = ClassOrInterface | Reference | Tuple | Anonymous | Mapped | ReverseMapped | EvolvingArray,
|
||||
|
||||
// Flags that require TypeFlags.Object
|
||||
ContainsSpread = 1 << 22, // Object literal contains spread operation
|
||||
ObjectRestType = 1 << 23, // Originates in object rest declaration
|
||||
InstantiationExpressionType = 1 << 24, // Originates in instantiation expression
|
||||
ContainsSpread = 1 << 21, // Object literal contains spread operation
|
||||
ObjectRestType = 1 << 22, // Originates in object rest declaration
|
||||
InstantiationExpressionType = 1 << 23, // Originates in instantiation expression
|
||||
/* @internal */
|
||||
IsClassInstanceClone = 1 << 25, // Type is a clone of a class instance type
|
||||
IsClassInstanceClone = 1 << 24, // Type is a clone of a class instance type
|
||||
// Flags that require TypeFlags.Object and ObjectFlags.Reference
|
||||
/* @internal */
|
||||
IdenticalBaseTypeCalculated = 1 << 26, // has had `getSingleBaseForNonAugmentingSubtype` invoked on it already
|
||||
IdenticalBaseTypeCalculated = 1 << 25, // has had `getSingleBaseForNonAugmentingSubtype` invoked on it already
|
||||
/* @internal */
|
||||
IdenticalBaseTypeExists = 1 << 27, // has a defined cachedEquivalentBaseType member
|
||||
IdenticalBaseTypeExists = 1 << 26, // has a defined cachedEquivalentBaseType member
|
||||
|
||||
// Flags that require TypeFlags.UnionOrIntersection or TypeFlags.Substitution
|
||||
/* @internal */
|
||||
IsGenericTypeComputed = 1 << 22, // IsGenericObjectType flag has been computed
|
||||
IsGenericTypeComputed = 1 << 21, // IsGenericObjectType flag has been computed
|
||||
/* @internal */
|
||||
IsGenericObjectType = 1 << 23, // Union or intersection contains generic object type
|
||||
IsGenericObjectType = 1 << 22, // Union or intersection contains generic object type
|
||||
/* @internal */
|
||||
IsGenericIndexType = 1 << 24, // Union or intersection contains generic index type
|
||||
IsGenericIndexType = 1 << 23, // Union or intersection contains generic index type
|
||||
/* @internal */
|
||||
IsGenericType = IsGenericObjectType | IsGenericIndexType,
|
||||
|
||||
// Flags that require TypeFlags.Union
|
||||
/* @internal */
|
||||
ContainsIntersections = 1 << 25, // Union contains intersections
|
||||
ContainsIntersections = 1 << 24, // Union contains intersections
|
||||
|
||||
// Flags that require TypeFlags.Intersection
|
||||
/* @internal */
|
||||
IsNeverIntersectionComputed = 1 << 25, // IsNeverLike flag has been computed
|
||||
IsNeverIntersectionComputed = 1 << 24, // IsNeverLike flag has been computed
|
||||
/* @internal */
|
||||
IsNeverIntersection = 1 << 26, // Intersection reduces to never
|
||||
IsNeverIntersection = 1 << 25, // Intersection reduces to never
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
@@ -7240,7 +7248,11 @@ namespace ts {
|
||||
// Signature elements
|
||||
//
|
||||
|
||||
createTypeParameterDeclaration(modifiers: readonly Modifier[] | undefined, name: string | Identifier, constraint?: TypeNode, defaultType?: TypeNode): TypeParameterDeclaration;
|
||||
/** @deprecated */
|
||||
createTypeParameterDeclaration(name: string | Identifier, constraint?: TypeNode, defaultType?: TypeNode): TypeParameterDeclaration;
|
||||
updateTypeParameterDeclaration(node: TypeParameterDeclaration, modifiers: readonly Modifier[] | undefined, name: Identifier, constraint: TypeNode | undefined, defaultType: TypeNode | undefined): TypeParameterDeclaration;
|
||||
/** @deprecated */
|
||||
updateTypeParameterDeclaration(node: TypeParameterDeclaration, name: Identifier, constraint: TypeNode | undefined, defaultType: TypeNode | undefined): TypeParameterDeclaration;
|
||||
createParameterDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, dotDotDotToken: DotDotDotToken | undefined, name: string | BindingName, questionToken?: QuestionToken, type?: TypeNode, initializer?: Expression): ParameterDeclaration;
|
||||
updateParameterDeclaration(node: ParameterDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, dotDotDotToken: DotDotDotToken | undefined, name: string | BindingName, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined): ParameterDeclaration;
|
||||
|
||||
@@ -5003,6 +5003,8 @@ namespace ts {
|
||||
case SyntaxKind.AsyncKeyword: return ModifierFlags.Async;
|
||||
case SyntaxKind.ReadonlyKeyword: return ModifierFlags.Readonly;
|
||||
case SyntaxKind.OverrideKeyword: return ModifierFlags.Override;
|
||||
case SyntaxKind.InKeyword: return ModifierFlags.In;
|
||||
case SyntaxKind.OutKeyword: return ModifierFlags.Out;
|
||||
}
|
||||
return ModifierFlags.None;
|
||||
}
|
||||
|
||||
@@ -1187,11 +1187,13 @@ namespace ts {
|
||||
case SyntaxKind.DeclareKeyword:
|
||||
case SyntaxKind.DefaultKeyword:
|
||||
case SyntaxKind.ExportKeyword:
|
||||
case SyntaxKind.InKeyword:
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
case SyntaxKind.ReadonlyKeyword:
|
||||
case SyntaxKind.StaticKeyword:
|
||||
case SyntaxKind.OutKeyword:
|
||||
case SyntaxKind.OverrideKeyword:
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -385,6 +385,7 @@ namespace ts {
|
||||
case SyntaxKind.TypeParameter:
|
||||
Debug.type<TypeParameterDeclaration>(node);
|
||||
return factory.updateTypeParameterDeclaration(node,
|
||||
nodesVisitor(node.modifiers, visitor, isModifier),
|
||||
nodeVisitor(node.name, visitor, isIdentifier),
|
||||
nodeVisitor(node.constraint, visitor, isTypeNode),
|
||||
nodeVisitor(node.default, visitor, isTypeNode));
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace ts.codefix {
|
||||
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, { container, typeNode, constraint, name }: Info): void {
|
||||
changes.replaceNode(sourceFile, container, factory.createMappedTypeNode(
|
||||
/*readonlyToken*/ undefined,
|
||||
factory.createTypeParameterDeclaration(name, factory.createTypeReferenceNode(constraint)),
|
||||
factory.createTypeParameterDeclaration(/*modifiers*/ undefined, name, factory.createTypeReferenceNode(constraint)),
|
||||
/*nameType*/ undefined,
|
||||
/*questionToken*/ undefined,
|
||||
typeNode,
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace ts.codefix {
|
||||
const members = isInterfaceDeclaration(container) ? container.members : (container.type as TypeLiteralNode).members;
|
||||
const otherMembers = members.filter(member => !isIndexSignatureDeclaration(member));
|
||||
const parameter = first(indexSignature.parameters);
|
||||
const mappedTypeParameter = factory.createTypeParameterDeclaration(cast(parameter.name, isIdentifier), parameter.type);
|
||||
const mappedTypeParameter = factory.createTypeParameterDeclaration(/*modifiers*/ undefined, cast(parameter.name, isIdentifier), parameter.type);
|
||||
const mappedIntersectionType = factory.createMappedTypeNode(
|
||||
hasEffectiveReadonlyModifier(indexSignature) ? factory.createModifier(SyntaxKind.ReadonlyKeyword) : undefined,
|
||||
mappedTypeParameter,
|
||||
|
||||
@@ -222,6 +222,7 @@ namespace ts.codefix {
|
||||
}
|
||||
return factory.updateTypeParameterDeclaration(
|
||||
typeParameterDecl,
|
||||
typeParameterDecl.modifiers,
|
||||
typeParameterDecl.name,
|
||||
constraint,
|
||||
defaultType
|
||||
@@ -306,7 +307,7 @@ namespace ts.codefix {
|
||||
const typeParameters = isJs || typeArguments === undefined
|
||||
? undefined
|
||||
: map(typeArguments, (_, i) =>
|
||||
factory.createTypeParameterDeclaration(CharacterCodes.T + typeArguments.length - 1 <= CharacterCodes.Z ? String.fromCharCode(CharacterCodes.T + i) : `T${i}`));
|
||||
factory.createTypeParameterDeclaration(/*modifiers*/ undefined, CharacterCodes.T + typeArguments.length - 1 <= CharacterCodes.Z ? String.fromCharCode(CharacterCodes.T + i) : `T${i}`));
|
||||
const parameters = createDummyParameters(args.length, names, types, /*minArgumentCount*/ undefined, isJs);
|
||||
const type = isJs || contextualType === undefined
|
||||
? undefined
|
||||
|
||||
@@ -203,7 +203,7 @@ namespace ts.refactor {
|
||||
/* decorators */ undefined,
|
||||
/* modifiers */ undefined,
|
||||
name,
|
||||
typeParameters.map(id => factory.updateTypeParameterDeclaration(id, id.name, id.constraint, /* defaultType */ undefined)),
|
||||
typeParameters.map(id => factory.updateTypeParameterDeclaration(id, id.modifiers, id.name, id.constraint, /* defaultType */ undefined)),
|
||||
selection
|
||||
);
|
||||
changes.insertNodeBefore(file, firstStatement, ignoreSourceNewlines(newTypeNode), /* blankLineBetween */ true);
|
||||
@@ -237,7 +237,7 @@ namespace ts.refactor {
|
||||
const templates: JSDocTemplateTag[] = [];
|
||||
forEach(typeParameters, typeParameter => {
|
||||
const constraint = getEffectiveConstraintOfTypeParameter(typeParameter);
|
||||
const parameter = factory.createTypeParameterDeclaration(typeParameter.name);
|
||||
const parameter = factory.createTypeParameterDeclaration(/*modifiers*/ undefined, typeParameter.name);
|
||||
const template = factory.createJSDocTemplateTag(
|
||||
factory.createIdentifier("template"),
|
||||
constraint && cast(constraint, isJSDocTypeExpression),
|
||||
|
||||
@@ -267,7 +267,7 @@ namespace ts {
|
||||
factory.createKeywordTypeNode(SyntaxKind.AnyKeyword)
|
||||
),
|
||||
factory.createFunctionTypeNode(
|
||||
[factory.createTypeParameterDeclaration("T")],
|
||||
[factory.createTypeParameterDeclaration(/*modifiers*/ undefined, "T")],
|
||||
[factory.createParameterDeclaration(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
|
||||
Reference in New Issue
Block a user