mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into release-2.7
This commit is contained in:
+30
-24
@@ -2289,30 +2289,13 @@ namespace ts {
|
||||
declareSymbol(file.symbol.exports, file.symbol, <PropertyAccessExpression>node.left, SymbolFlags.Property | SymbolFlags.ExportValue, SymbolFlags.None);
|
||||
}
|
||||
|
||||
function isExportsOrModuleExportsOrAlias(node: Node): boolean {
|
||||
return isExportsIdentifier(node) ||
|
||||
isModuleExportsPropertyAccessExpression(node) ||
|
||||
isIdentifier(node) && isNameOfExportsOrModuleExportsAliasDeclaration(node);
|
||||
}
|
||||
|
||||
function isNameOfExportsOrModuleExportsAliasDeclaration(node: Identifier): boolean {
|
||||
const symbol = lookupSymbolForName(node.escapedText);
|
||||
return symbol && symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration) &&
|
||||
symbol.valueDeclaration.initializer && isExportsOrModuleExportsOrAliasOrAssignment(symbol.valueDeclaration.initializer);
|
||||
}
|
||||
|
||||
function isExportsOrModuleExportsOrAliasOrAssignment(node: Node): boolean {
|
||||
return isExportsOrModuleExportsOrAlias(node) ||
|
||||
(isAssignmentExpression(node, /*excludeCompoundAssignements*/ true) && (isExportsOrModuleExportsOrAliasOrAssignment(node.left) || isExportsOrModuleExportsOrAliasOrAssignment(node.right)));
|
||||
}
|
||||
|
||||
function bindModuleExportsAssignment(node: BinaryExpression) {
|
||||
// A common practice in node modules is to set 'export = module.exports = {}', this ensures that 'exports'
|
||||
// is still pointing to 'module.exports'.
|
||||
// We do not want to consider this as 'export=' since a module can have only one of these.
|
||||
// Similarly we do not want to treat 'module.exports = exports' as an 'export='.
|
||||
const assignedExpression = getRightMostAssignedExpression(node.right);
|
||||
if (isEmptyObjectLiteral(assignedExpression) || isExportsOrModuleExportsOrAlias(assignedExpression)) {
|
||||
if (isEmptyObjectLiteral(assignedExpression) || container === file && isExportsOrModuleExportsOrAlias(file, assignedExpression)) {
|
||||
// Mark it as a module in case there are no other exports in the file
|
||||
setCommonJsModuleIndicator(node);
|
||||
return;
|
||||
@@ -2393,7 +2376,7 @@ namespace ts {
|
||||
if (node.kind === SyntaxKind.BinaryExpression) {
|
||||
leftSideOfAssignment.parent = node;
|
||||
}
|
||||
if (isNameOfExportsOrModuleExportsAliasDeclaration(target)) {
|
||||
if (container === file && isNameOfExportsOrModuleExportsAliasDeclaration(file, target)) {
|
||||
// This can be an alias for the 'exports' or 'module.exports' names, e.g.
|
||||
// var util = module.exports;
|
||||
// util.property = function ...
|
||||
@@ -2406,11 +2389,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function lookupSymbolForName(name: __String) {
|
||||
const local = container.locals && container.locals.get(name);
|
||||
if (local) {
|
||||
return local.exportSymbol || local;
|
||||
}
|
||||
return container.symbol && container.symbol.exports && container.symbol.exports.get(name);
|
||||
return lookupSymbolForNameWorker(container, name);
|
||||
}
|
||||
|
||||
function bindPropertyAssignment(functionName: __String, propertyAccess: PropertyAccessExpression, isPrototypeProperty: boolean) {
|
||||
@@ -2649,6 +2628,33 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function isExportsOrModuleExportsOrAlias(sourceFile: SourceFile, node: Expression): boolean {
|
||||
return isExportsIdentifier(node) ||
|
||||
isModuleExportsPropertyAccessExpression(node) ||
|
||||
isIdentifier(node) && isNameOfExportsOrModuleExportsAliasDeclaration(sourceFile, node);
|
||||
}
|
||||
|
||||
function isNameOfExportsOrModuleExportsAliasDeclaration(sourceFile: SourceFile, node: Identifier): boolean {
|
||||
const symbol = lookupSymbolForNameWorker(sourceFile, node.escapedText);
|
||||
return symbol && symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration) &&
|
||||
symbol.valueDeclaration.initializer && isExportsOrModuleExportsOrAliasOrAssignment(sourceFile, symbol.valueDeclaration.initializer);
|
||||
}
|
||||
|
||||
function isExportsOrModuleExportsOrAliasOrAssignment(sourceFile: SourceFile, node: Expression): boolean {
|
||||
return isExportsOrModuleExportsOrAlias(sourceFile, node) ||
|
||||
(isAssignmentExpression(node, /*excludeCompoundAssignements*/ true) && (
|
||||
isExportsOrModuleExportsOrAliasOrAssignment(sourceFile, node.left) || isExportsOrModuleExportsOrAliasOrAssignment(sourceFile, node.right)));
|
||||
}
|
||||
|
||||
function lookupSymbolForNameWorker(container: Node, name: __String): Symbol | undefined {
|
||||
const local = container.locals && container.locals.get(name);
|
||||
if (local) {
|
||||
return local.exportSymbol || local;
|
||||
}
|
||||
return container.symbol && container.symbol.exports && container.symbol.exports.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the transform flags for a node, given the transform flags of its subtree
|
||||
*
|
||||
|
||||
+40
-20
@@ -268,8 +268,8 @@ namespace ts {
|
||||
getSuggestionForNonexistentSymbol: (location, name, meaning) => getSuggestionForNonexistentSymbol(location, escapeLeadingUnderscores(name), meaning),
|
||||
getBaseConstraintOfType,
|
||||
getDefaultFromTypeParameter: type => type && type.flags & TypeFlags.TypeParameter ? getDefaultFromTypeParameter(type as TypeParameter) : undefined,
|
||||
resolveName(name, location, meaning) {
|
||||
return resolveName(location, escapeLeadingUnderscores(name), meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false);
|
||||
resolveName(name, location, meaning, excludeGlobals) {
|
||||
return resolveName(location, escapeLeadingUnderscores(name), meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false, excludeGlobals);
|
||||
},
|
||||
getJsxNamespace: () => unescapeLeadingUnderscores(getJsxNamespace()),
|
||||
getAccessibleSymbolChain,
|
||||
@@ -952,8 +952,9 @@ namespace ts {
|
||||
nameNotFoundMessage: DiagnosticMessage | undefined,
|
||||
nameArg: __String | Identifier,
|
||||
isUse: boolean,
|
||||
excludeGlobals = false,
|
||||
suggestedNameNotFoundMessage?: DiagnosticMessage): Symbol {
|
||||
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, getSymbol, suggestedNameNotFoundMessage);
|
||||
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol, suggestedNameNotFoundMessage);
|
||||
}
|
||||
|
||||
function resolveNameHelper(
|
||||
@@ -963,6 +964,7 @@ namespace ts {
|
||||
nameNotFoundMessage: DiagnosticMessage,
|
||||
nameArg: __String | Identifier,
|
||||
isUse: boolean,
|
||||
excludeGlobals: boolean,
|
||||
lookup: typeof getSymbol,
|
||||
suggestedNameNotFoundMessage?: DiagnosticMessage): Symbol {
|
||||
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
|
||||
@@ -1209,7 +1211,9 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
result = lookup(globals, name, meaning);
|
||||
if (!excludeGlobals) {
|
||||
result = lookup(globals, name, meaning);
|
||||
}
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
@@ -11277,6 +11281,9 @@ namespace ts {
|
||||
}
|
||||
diagnostic = Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type;
|
||||
break;
|
||||
case SyntaxKind.MappedType:
|
||||
error(declaration, Diagnostics.Mapped_object_type_implicitly_has_an_any_template_type);
|
||||
return;
|
||||
default:
|
||||
diagnostic = Diagnostics.Variable_0_implicitly_has_an_1_type;
|
||||
}
|
||||
@@ -11889,6 +11896,7 @@ namespace ts {
|
||||
Diagnostics.Cannot_find_name_0,
|
||||
node,
|
||||
!isWriteOnlyAccess(node),
|
||||
/*excludeGlobals*/ false,
|
||||
Diagnostics.Cannot_find_name_0_Did_you_mean_1) || unknownSymbol;
|
||||
}
|
||||
return links.resolvedSymbol;
|
||||
@@ -15154,7 +15162,7 @@ namespace ts {
|
||||
* element is not a class element, or the class element type cannot be determined, returns 'undefined'.
|
||||
* For example, in the element <MyClass>, the element instance type is `MyClass` (not `typeof MyClass`).
|
||||
*/
|
||||
function getJsxElementInstanceType(node: JsxOpeningLikeElement, valueType: Type, sourceAttributesType: Type) {
|
||||
function getJsxElementInstanceType(node: JsxOpeningLikeElement, valueType: Type, sourceAttributesType: Type | undefined) {
|
||||
Debug.assert(!(valueType.flags & TypeFlags.Union));
|
||||
if (isTypeAny(valueType)) {
|
||||
// Short-circuit if the class tag is using an element type 'any'
|
||||
@@ -15173,20 +15181,27 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
const instantiatedSignatures = [];
|
||||
for (const signature of signatures) {
|
||||
if (signature.typeParameters) {
|
||||
const isJavascript = isInJavaScriptFile(node);
|
||||
const inferenceContext = createInferenceContext(signature, /*flags*/ isJavascript ? InferenceFlags.AnyDefault : 0);
|
||||
const typeArguments = inferJsxTypeArguments(signature, sourceAttributesType, inferenceContext);
|
||||
instantiatedSignatures.push(getSignatureInstantiation(signature, typeArguments, isJavascript));
|
||||
if (sourceAttributesType) {
|
||||
// Instantiate in context of source type
|
||||
const instantiatedSignatures = [];
|
||||
for (const signature of signatures) {
|
||||
if (signature.typeParameters) {
|
||||
const isJavascript = isInJavaScriptFile(node);
|
||||
const inferenceContext = createInferenceContext(signature, /*flags*/ isJavascript ? InferenceFlags.AnyDefault : 0);
|
||||
const typeArguments = inferJsxTypeArguments(signature, sourceAttributesType, inferenceContext);
|
||||
instantiatedSignatures.push(getSignatureInstantiation(signature, typeArguments, isJavascript));
|
||||
}
|
||||
else {
|
||||
instantiatedSignatures.push(signature);
|
||||
}
|
||||
}
|
||||
else {
|
||||
instantiatedSignatures.push(signature);
|
||||
}
|
||||
}
|
||||
|
||||
return getUnionType(map(instantiatedSignatures, getReturnTypeOfSignature), UnionReduction.Subtype);
|
||||
return getUnionType(map(instantiatedSignatures, getReturnTypeOfSignature), UnionReduction.Subtype);
|
||||
}
|
||||
else {
|
||||
// Do not instantiate if no source type is provided - type parameters and their constraints will be used by contextual typing
|
||||
return getUnionType(map(signatures, getReturnTypeOfSignature), UnionReduction.Subtype);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -15410,7 +15425,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Get the element instance type (the result of newing or invoking this tag)
|
||||
const elemInstanceType = getJsxElementInstanceType(openingLikeElement, elementType, sourceAttributesType || emptyObjectType);
|
||||
const elemInstanceType = getJsxElementInstanceType(openingLikeElement, elementType, sourceAttributesType);
|
||||
|
||||
// If we should include all stateless attributes type, then get all attributes type from all stateless function signature.
|
||||
// Otherwise get only attributes type from the signature picked by choose-overload logic.
|
||||
@@ -16068,7 +16083,7 @@ namespace ts {
|
||||
|
||||
function getSuggestionForNonexistentSymbol(location: Node, outerName: __String, meaning: SymbolFlags): string {
|
||||
Debug.assert(outerName !== undefined, "outername should always be defined");
|
||||
const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, (symbols, name, meaning) => {
|
||||
const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, (symbols, name, meaning) => {
|
||||
Debug.assertEqual(outerName, name, "name should equal outerName");
|
||||
const symbol = getSymbol(symbols, name, meaning);
|
||||
// Sometimes the symbol is found when location is a return type of a function: `typeof x` and `x` is declared in the body of the function
|
||||
@@ -20307,6 +20322,11 @@ namespace ts {
|
||||
function checkMappedType(node: MappedTypeNode) {
|
||||
checkSourceElement(node.typeParameter);
|
||||
checkSourceElement(node.type);
|
||||
|
||||
if (noImplicitAny && !node.type) {
|
||||
reportImplicitAnyError(node, anyType);
|
||||
}
|
||||
|
||||
const type = <MappedType>getTypeFromMappedTypeNode(node);
|
||||
const constraintType = getConstraintTypeFromMappedType(type);
|
||||
checkTypeAssignableTo(constraintType, stringType, node.typeParameter.constraint);
|
||||
@@ -22985,7 +23005,7 @@ namespace ts {
|
||||
Diagnostics.Property_0_in_type_1_is_not_assignable_to_the_same_property_in_base_type_2,
|
||||
unescapeLeadingUnderscores(declaredProp.escapedName),
|
||||
typeToString(typeWithThis),
|
||||
typeToString(getTypeOfSymbol(baseProp))
|
||||
typeToString(baseWithThis)
|
||||
);
|
||||
if (!checkTypeAssignableTo(getTypeOfSymbol(prop), getTypeOfSymbol(baseProp), member.name || member, /*message*/ undefined, rootChain)) {
|
||||
issuedMemberError = true;
|
||||
|
||||
+20
-7
@@ -412,12 +412,14 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
export function mapIterator<T, U>(iter: Iterator<T>, mapFn: (x: T) => U): Iterator<U> {
|
||||
return { next };
|
||||
function next(): { value: U, done: false } | { value: never, done: true } {
|
||||
const iterRes = iter.next();
|
||||
return iterRes.done ? iterRes : { value: mapFn(iterRes.value), done: false };
|
||||
}
|
||||
return {
|
||||
next() {
|
||||
const iterRes = iter.next();
|
||||
return iterRes.done ? iterRes : { value: mapFn(iterRes.value), done: false };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Maps from T to T and avoids allocation if all elements map to themselves
|
||||
@@ -551,12 +553,23 @@ namespace ts {
|
||||
return result || array;
|
||||
}
|
||||
|
||||
export function mapAllOrFail<T, U>(array: ReadonlyArray<T>, mapFn: (x: T, i: number) => U | undefined): U[] | undefined {
|
||||
const result: U[] = [];
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
const mapped = mapFn(array[i], i);
|
||||
if (mapped === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
result.push(mapped);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function mapDefined<T, U>(array: ReadonlyArray<T> | undefined, mapFn: (x: T, i: number) => U | undefined): U[] {
|
||||
const result: U[] = [];
|
||||
if (array) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
const item = array[i];
|
||||
const mapped = mapFn(item, i);
|
||||
const mapped = mapFn(array[i], i);
|
||||
if (mapped !== undefined) {
|
||||
result.push(mapped);
|
||||
}
|
||||
|
||||
@@ -3571,7 +3571,10 @@
|
||||
"category": "Error",
|
||||
"code": 7038
|
||||
},
|
||||
|
||||
"Mapped object type implicitly has an 'any' template type.": {
|
||||
"category": "Error",
|
||||
"code": 7039
|
||||
},
|
||||
"You cannot rename this element.": {
|
||||
"category": "Error",
|
||||
"code": 8000
|
||||
@@ -3874,6 +3877,10 @@
|
||||
"category": "Message",
|
||||
"code": 90028
|
||||
},
|
||||
"Add async modifier to containing function": {
|
||||
"category": "Message",
|
||||
"code": 90029
|
||||
},
|
||||
"Convert function to an ES2015 class": {
|
||||
"category": "Message",
|
||||
"code": 95001
|
||||
@@ -3937,5 +3944,9 @@
|
||||
"Use synthetic 'default' member.": {
|
||||
"category": "Message",
|
||||
"code": 95016
|
||||
},
|
||||
"Convert to ES6 module": {
|
||||
"category": "Message",
|
||||
"code": 95017
|
||||
}
|
||||
}
|
||||
|
||||
+8
-20
@@ -1194,27 +1194,15 @@ namespace ts {
|
||||
//
|
||||
|
||||
function emitObjectBindingPattern(node: ObjectBindingPattern) {
|
||||
const elements = node.elements;
|
||||
if (elements.length === 0) {
|
||||
write("{}");
|
||||
}
|
||||
else {
|
||||
write("{");
|
||||
emitList(node, elements, ListFormat.ObjectBindingPatternElements);
|
||||
write("}");
|
||||
}
|
||||
write("{");
|
||||
emitList(node, node.elements, ListFormat.ObjectBindingPatternElements);
|
||||
write("}");
|
||||
}
|
||||
|
||||
function emitArrayBindingPattern(node: ArrayBindingPattern) {
|
||||
const elements = node.elements;
|
||||
if (elements.length === 0) {
|
||||
write("[]");
|
||||
}
|
||||
else {
|
||||
write("[");
|
||||
emitList(node, node.elements, ListFormat.ArrayBindingPatternElements);
|
||||
write("]");
|
||||
}
|
||||
write("[");
|
||||
emitList(node, node.elements, ListFormat.ArrayBindingPatternElements);
|
||||
write("]");
|
||||
}
|
||||
|
||||
function emitBindingElement(node: BindingElement) {
|
||||
@@ -3167,8 +3155,8 @@ namespace ts {
|
||||
TupleTypeElements = CommaDelimited | SpaceBetweenSiblings | SingleLine | Indented,
|
||||
UnionTypeConstituents = BarDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
IntersectionTypeConstituents = AmpersandDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
ObjectBindingPatternElements = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings,
|
||||
ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings,
|
||||
ObjectBindingPatternElements = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings | NoSpaceIfEmpty,
|
||||
ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings | NoSpaceIfEmpty,
|
||||
ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces | NoSpaceIfEmpty,
|
||||
ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets,
|
||||
CommaListElements = CommaDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
|
||||
@@ -71,11 +71,11 @@ namespace ts {
|
||||
// Literals
|
||||
|
||||
/** If a node is passed, creates a string literal whose source text is read from a source node during emit. */
|
||||
export function createLiteral(value: string | StringLiteral | NumericLiteral | Identifier): StringLiteral;
|
||||
export function createLiteral(value: string | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | Identifier): StringLiteral;
|
||||
export function createLiteral(value: number): NumericLiteral;
|
||||
export function createLiteral(value: boolean): BooleanLiteral;
|
||||
export function createLiteral(value: string | number | boolean): PrimaryExpression;
|
||||
export function createLiteral(value: string | number | boolean | StringLiteral | NumericLiteral | Identifier): PrimaryExpression {
|
||||
export function createLiteral(value: string | number | boolean | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | Identifier): PrimaryExpression {
|
||||
if (typeof value === "number") {
|
||||
return createNumericLiteral(value + "");
|
||||
}
|
||||
@@ -101,7 +101,7 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
function createLiteralFromNode(sourceNode: StringLiteral | NumericLiteral | Identifier): StringLiteral {
|
||||
function createLiteralFromNode(sourceNode: StringLiteralLike | NumericLiteral | Identifier): StringLiteral {
|
||||
const node = createStringLiteral(getTextOfIdentifierOrLiteral(sourceNode));
|
||||
node.textSourceNode = sourceNode;
|
||||
return node;
|
||||
@@ -3626,7 +3626,7 @@ namespace ts {
|
||||
return qualifiedName;
|
||||
}
|
||||
|
||||
export function convertToFunctionBody(node: ConciseBody, multiLine?: boolean) {
|
||||
export function convertToFunctionBody(node: ConciseBody, multiLine?: boolean): Block {
|
||||
return isBlock(node) ? node : setTextRange(createBlock([setTextRange(createReturn(node), node)], multiLine), node);
|
||||
}
|
||||
|
||||
|
||||
+4
-18
@@ -786,15 +786,7 @@ namespace ts {
|
||||
const comments = getJSDocCommentRanges(node, sourceFile.text);
|
||||
if (comments) {
|
||||
for (const comment of comments) {
|
||||
const jsDoc = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos);
|
||||
if (jsDoc) {
|
||||
if (!node.jsDoc) {
|
||||
node.jsDoc = [jsDoc];
|
||||
}
|
||||
else {
|
||||
node.jsDoc.push(jsDoc);
|
||||
}
|
||||
}
|
||||
node.jsDoc = append(node.jsDoc, JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6499,7 +6491,7 @@ namespace ts {
|
||||
if (state === JSDocState.BeginningOfLine) {
|
||||
// leading asterisks start recording on the *next* (non-whitespace) token
|
||||
state = JSDocState.SawAsterisk;
|
||||
indent += scanner.getTokenText().length;
|
||||
indent += 1;
|
||||
break;
|
||||
}
|
||||
// record the * as a comment
|
||||
@@ -6611,10 +6603,7 @@ namespace ts {
|
||||
const start = scanner.getStartPos();
|
||||
let children: JSDocParameterTag[];
|
||||
while (child = tryParse(() => parseChildParameterOrPropertyTag(PropertyLikeParse.Parameter, name))) {
|
||||
if (!children) {
|
||||
children = [];
|
||||
}
|
||||
children.push(child);
|
||||
children = append(children, child);
|
||||
}
|
||||
if (children) {
|
||||
jsdocTypeLiteral = <JSDocTypeLiteral>createNode(SyntaxKind.JSDocTypeLiteral, start);
|
||||
@@ -6731,10 +6720,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!jsdocTypeLiteral.jsDocPropertyTags) {
|
||||
jsdocTypeLiteral.jsDocPropertyTags = [] as MutableNodeArray<JSDocPropertyTag>;
|
||||
}
|
||||
(jsdocTypeLiteral.jsDocPropertyTags as MutableNodeArray<JSDocPropertyTag>).push(child);
|
||||
jsdocTypeLiteral.jsDocPropertyTags = append(jsdocTypeLiteral.jsDocPropertyTags as MutableNodeArray<JSDocPropertyTag>, child);
|
||||
}
|
||||
}
|
||||
if (jsdocTypeLiteral) {
|
||||
|
||||
@@ -1149,11 +1149,13 @@ namespace ts {
|
||||
|
||||
export interface StringLiteral extends LiteralExpression {
|
||||
kind: SyntaxKind.StringLiteral;
|
||||
/* @internal */ textSourceNode?: Identifier | StringLiteral | NumericLiteral; // Allows a StringLiteral to get its text from another node (used by transforms).
|
||||
/* @internal */ textSourceNode?: Identifier | StringLiteralLike | NumericLiteral; // Allows a StringLiteral to get its text from another node (used by transforms).
|
||||
/** Note: this is only set when synthesizing a node, not during parsing. */
|
||||
/* @internal */ singleQuote?: boolean;
|
||||
}
|
||||
|
||||
/* @internal */ export type StringLiteralLike = StringLiteral | NoSubstitutionTemplateLiteral;
|
||||
|
||||
// Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing.
|
||||
// Consider 'Expression'. Without the brand, 'Expression' is actually no different
|
||||
// (structurally) than 'Node'. Because of this you can pass any Node to a function that
|
||||
@@ -1499,6 +1501,7 @@ namespace ts {
|
||||
kind: SyntaxKind.ArrowFunction;
|
||||
equalsGreaterThanToken: EqualsGreaterThanToken;
|
||||
body: ConciseBody;
|
||||
name: never;
|
||||
}
|
||||
|
||||
// The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral,
|
||||
@@ -2156,6 +2159,7 @@ namespace ts {
|
||||
export interface ExportDeclaration extends DeclarationStatement {
|
||||
kind: SyntaxKind.ExportDeclaration;
|
||||
parent?: SourceFile | ModuleBlock;
|
||||
/** Will not be assigned in the case of `export * from "foo";` */
|
||||
exportClause?: NamedExports;
|
||||
/** If this is not a StringLiteral it will be a grammar error. */
|
||||
moduleSpecifier?: Expression;
|
||||
@@ -2878,7 +2882,7 @@ namespace ts {
|
||||
*/
|
||||
/* @internal */ isArrayLikeType(type: Type): boolean;
|
||||
/* @internal */ getAllPossiblePropertiesOfTypes(type: ReadonlyArray<Type>): Symbol[];
|
||||
/* @internal */ resolveName(name: string, location: Node, meaning: SymbolFlags): Symbol | undefined;
|
||||
/* @internal */ resolveName(name: string, location: Node, meaning: SymbolFlags, excludeGlobals: boolean): Symbol | undefined;
|
||||
/* @internal */ getJsxNamespace(): string;
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace ts {
|
||||
export const emptyArray: never[] = [] as never[];
|
||||
export const resolvingEmptyArray: never[] = [] as never[];
|
||||
export const emptyMap: ReadonlyMap<never> = createMap<never>();
|
||||
export const emptyUnderscoreEscapedMap: ReadonlyUnderscoreEscapedMap<never> = emptyMap as ReadonlyUnderscoreEscapedMap<never>;
|
||||
|
||||
export const externalHelpersModuleNameText = "tslib";
|
||||
|
||||
@@ -1419,6 +1420,8 @@ namespace ts {
|
||||
* exactly one argument (of the form 'require("name")').
|
||||
* This function does not test if the node is in a JavaScript file or not.
|
||||
*/
|
||||
export function isRequireCall(callExpression: Node, checkArgumentIsStringLiteral: true): callExpression is CallExpression & { expression: Identifier, arguments: [StringLiteralLike] };
|
||||
export function isRequireCall(callExpression: Node, checkArgumentIsStringLiteral: boolean): callExpression is CallExpression;
|
||||
export function isRequireCall(callExpression: Node, checkArgumentIsStringLiteral: boolean): callExpression is CallExpression {
|
||||
if (callExpression.kind !== SyntaxKind.CallExpression) {
|
||||
return false;
|
||||
@@ -1456,7 +1459,7 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getRightMostAssignedExpression(node: Node) {
|
||||
export function getRightMostAssignedExpression(node: Expression): Expression {
|
||||
while (isAssignmentExpression(node, /*excludeCompoundAssignements*/ true)) {
|
||||
node = node.right;
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ namespace FourSlash {
|
||||
const ranges = this.getRanges();
|
||||
assert(ranges.length);
|
||||
for (const range of ranges) {
|
||||
this.goToRangeStart(range);
|
||||
this.selectRange(range);
|
||||
action();
|
||||
}
|
||||
}
|
||||
@@ -482,6 +482,11 @@ namespace FourSlash {
|
||||
this.selectionEnd = end.position;
|
||||
}
|
||||
|
||||
public selectRange(range: Range): void {
|
||||
this.goToRangeStart(range);
|
||||
this.selectionEnd = range.end;
|
||||
}
|
||||
|
||||
public moveCaretRight(count = 1) {
|
||||
this.currentCaretPosition += count;
|
||||
this.currentCaretPosition = Math.min(this.currentCaretPosition, this.getFileContent(this.activeFile.fileName).length);
|
||||
@@ -3835,6 +3840,10 @@ namespace FourSlashInterface {
|
||||
public select(startMarker: string, endMarker: string) {
|
||||
this.state.select(startMarker, endMarker);
|
||||
}
|
||||
|
||||
public selectRange(range: FourSlash.Range): void {
|
||||
this.state.selectRange(range);
|
||||
}
|
||||
}
|
||||
|
||||
export class VerifyNegatable {
|
||||
|
||||
@@ -6488,4 +6488,76 @@ namespace ts.projectSystem {
|
||||
verifyWatchedDirectories(/*useProjectAtRoot*/ false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("tsserverProjectSystem typingsInstaller on inferred Project", () => {
|
||||
it("when projectRootPath is provided", () => {
|
||||
const projects = "/users/username/projects";
|
||||
const projectRootPath = `${projects}/san2`;
|
||||
const file: FileOrFolder = {
|
||||
path: `${projectRootPath}/x.js`,
|
||||
content: "const aaaaaaav = 1;"
|
||||
};
|
||||
|
||||
const currentDirectory = `${projects}/anotherProject`;
|
||||
const packageJsonInCurrentDirectory: FileOrFolder = {
|
||||
path: `${currentDirectory}/package.json`,
|
||||
content: JSON.stringify({
|
||||
devDependencies: {
|
||||
pkgcurrentdirectory: ""
|
||||
},
|
||||
})
|
||||
};
|
||||
const packageJsonOfPkgcurrentdirectory: FileOrFolder = {
|
||||
path: `${currentDirectory}/node_modules/pkgcurrentdirectory/package.json`,
|
||||
content: JSON.stringify({
|
||||
name: "pkgcurrentdirectory",
|
||||
main: "index.js",
|
||||
typings: "index.d.ts"
|
||||
})
|
||||
};
|
||||
const indexOfPkgcurrentdirectory: FileOrFolder = {
|
||||
path: `${currentDirectory}/node_modules/pkgcurrentdirectory/index.d.ts`,
|
||||
content: "export function foo() { }"
|
||||
};
|
||||
|
||||
const typingsCache = `/users/username/Library/Caches/typescript/2.7`;
|
||||
const typingsCachePackageJson: FileOrFolder = {
|
||||
path: `${typingsCache}/package.json`,
|
||||
content: JSON.stringify({
|
||||
devDependencies: {
|
||||
},
|
||||
})
|
||||
};
|
||||
|
||||
const files = [file, packageJsonInCurrentDirectory, packageJsonOfPkgcurrentdirectory, indexOfPkgcurrentdirectory, typingsCachePackageJson];
|
||||
const host = createServerHost(files, { currentDirectory });
|
||||
|
||||
const typesRegistry = createMap<void>();
|
||||
typesRegistry.set("pkgcurrentdirectory", void 0);
|
||||
const typingsInstaller = new TestTypingsInstaller(typingsCache, /*throttleLimit*/ 5, host, typesRegistry);
|
||||
|
||||
const projectService = createProjectService(host, { typingsInstaller });
|
||||
|
||||
projectService.setCompilerOptionsForInferredProjects({
|
||||
module: ModuleKind.CommonJS,
|
||||
target: ScriptTarget.ES2016,
|
||||
jsx: JsxEmit.Preserve,
|
||||
experimentalDecorators: true,
|
||||
allowJs: true,
|
||||
allowSyntheticDefaultImports: true,
|
||||
allowNonTsExtensions: true
|
||||
});
|
||||
|
||||
projectService.openClientFile(file.path, file.content, ScriptKind.JS, projectRootPath);
|
||||
|
||||
const project = projectService.inferredProjects[0];
|
||||
assert.isDefined(project);
|
||||
|
||||
// Ensure that we use result from types cache when getting ls
|
||||
assert.isDefined(project.getLanguageService());
|
||||
|
||||
// Verify that the pkgcurrentdirectory from the current directory isnt picked up
|
||||
checkProjectActualFiles(project, [file.path]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -547,7 +547,7 @@ interface Array<T> {}`
|
||||
}
|
||||
|
||||
readDirectory(path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>, depth?: number): string[] {
|
||||
return ts.matchFiles(this.toNormalizedAbsolutePath(path), extensions, exclude, include, this.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, (dir) => {
|
||||
return ts.matchFiles(path, extensions, exclude, include, this.useCaseSensitiveFileNames, this.getCurrentDirectory(), depth, (dir) => {
|
||||
const directories: string[] = [];
|
||||
const files: string[] = [];
|
||||
const dirEntry = this.fs.get(this.toPath(dir));
|
||||
|
||||
Vendored
+1
-1
@@ -58,7 +58,7 @@ interface ReadonlySet<T> {
|
||||
readonly size: number;
|
||||
}
|
||||
|
||||
interface WeakSet<T> {
|
||||
interface WeakSet<T extends object> {
|
||||
add(value: T): this;
|
||||
delete(value: T): boolean;
|
||||
has(value: T): boolean;
|
||||
|
||||
Vendored
+1
-1
@@ -180,7 +180,7 @@ interface SetConstructor {
|
||||
new <T>(iterable: Iterable<T>): Set<T>;
|
||||
}
|
||||
|
||||
interface WeakSet<T> { }
|
||||
interface WeakSet<T extends object> { }
|
||||
|
||||
interface WeakSetConstructor {
|
||||
new <T extends object>(iterable: Iterable<T>): WeakSet<T>;
|
||||
|
||||
Vendored
+1
-1
@@ -118,7 +118,7 @@ interface Set<T> {
|
||||
readonly [Symbol.toStringTag]: "Set";
|
||||
}
|
||||
|
||||
interface WeakSet<T> {
|
||||
interface WeakSet<T extends object> {
|
||||
readonly [Symbol.toStringTag]: "WeakSet";
|
||||
}
|
||||
|
||||
|
||||
+1
-14
@@ -34,19 +34,6 @@ namespace ts.server {
|
||||
export type Types = Msg;
|
||||
}
|
||||
|
||||
function getProjectRootPath(project: Project): Path {
|
||||
switch (project.projectKind) {
|
||||
case ProjectKind.Configured:
|
||||
return <Path>getDirectoryPath(project.getProjectName());
|
||||
case ProjectKind.Inferred:
|
||||
// TODO: fixme
|
||||
return <Path>"";
|
||||
case ProjectKind.External:
|
||||
const projectName = normalizeSlashes(project.getProjectName());
|
||||
return <Path>getDirectoryPath(projectName);
|
||||
}
|
||||
}
|
||||
|
||||
export function createInstallTypingsRequest(project: Project, typeAcquisition: TypeAcquisition, unresolvedImports: SortedReadonlyArray<string>, cachePath?: string): DiscoverTypings {
|
||||
return {
|
||||
projectName: project.getProjectName(),
|
||||
@@ -54,7 +41,7 @@ namespace ts.server {
|
||||
compilerOptions: project.getCompilationSettings(),
|
||||
typeAcquisition,
|
||||
unresolvedImports,
|
||||
projectRootPath: getProjectRootPath(project),
|
||||
projectRootPath: project.getCurrentDirectory() as Path,
|
||||
cachePath,
|
||||
kind: "discover"
|
||||
};
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/* @internal */
|
||||
namespace ts.codefix {
|
||||
const fixId = "fixAwaitInSyncFunction";
|
||||
const errorCodes = [
|
||||
Diagnostics.await_expression_is_only_allowed_within_an_async_function.code,
|
||||
Diagnostics.A_for_await_of_statement_is_only_allowed_within_an_async_function_or_async_generator.code,
|
||||
];
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions(context) {
|
||||
const { sourceFile, span } = context;
|
||||
const nodes = getNodes(sourceFile, span.start);
|
||||
if (!nodes) return undefined;
|
||||
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, nodes));
|
||||
return [{ description: getLocaleSpecificMessage(Diagnostics.Add_async_modifier_to_containing_function), changes, fixId }];
|
||||
},
|
||||
fixIds: [fixId],
|
||||
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => {
|
||||
const nodes = getNodes(diag.file, diag.start);
|
||||
if (!nodes) return;
|
||||
doChange(changes, context.sourceFile, nodes);
|
||||
}),
|
||||
});
|
||||
|
||||
function getReturnType(expr: FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction) {
|
||||
if (expr.type) {
|
||||
return expr.type;
|
||||
}
|
||||
if (isVariableDeclaration(expr.parent) &&
|
||||
expr.parent.type &&
|
||||
isFunctionTypeNode(expr.parent.type)) {
|
||||
return expr.parent.type.type;
|
||||
}
|
||||
}
|
||||
|
||||
function getNodes(sourceFile: SourceFile, start: number): { insertBefore: Node, returnType: TypeNode | undefined } | undefined {
|
||||
const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false);
|
||||
const containingFunction = getContainingFunction(token);
|
||||
let insertBefore: Node | undefined;
|
||||
switch (containingFunction.kind) {
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
insertBefore = containingFunction.name;
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
insertBefore = findChildOfKind(containingFunction, SyntaxKind.FunctionKeyword, sourceFile);
|
||||
break;
|
||||
case SyntaxKind.ArrowFunction:
|
||||
insertBefore = findChildOfKind(containingFunction, SyntaxKind.OpenParenToken, sourceFile) || first(containingFunction.parameters);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
insertBefore,
|
||||
returnType: getReturnType(containingFunction)
|
||||
};
|
||||
}
|
||||
|
||||
function doChange(
|
||||
changes: textChanges.ChangeTracker,
|
||||
sourceFile: SourceFile,
|
||||
{ insertBefore, returnType }: { insertBefore: Node | undefined, returnType: TypeNode | undefined }): void {
|
||||
|
||||
if (returnType) {
|
||||
const entityName = getEntityNameFromTypeNode(returnType);
|
||||
if (!entityName || entityName.kind !== SyntaxKind.Identifier || entityName.text !== "Promise") {
|
||||
changes.replaceNode(sourceFile, returnType, createTypeReferenceNode("Promise", createNodeArray([returnType])));
|
||||
}
|
||||
}
|
||||
changes.insertModifierBefore(sourceFile, SyntaxKind.AsyncKeyword, insertBefore);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
/// <reference path="fixForgottenThisPropertyAccess.ts" />
|
||||
/// <reference path='fixUnusedIdentifier.ts' />
|
||||
/// <reference path='fixJSDocTypes.ts' />
|
||||
/// <reference path='fixAwaitInSyncFunction.ts' />
|
||||
/// <reference path='importFixes.ts' />
|
||||
/// <reference path='disableJsDiagnostics.ts' />
|
||||
/// <reference path='helpers.ts' />
|
||||
|
||||
@@ -746,7 +746,7 @@ namespace ts.codefix {
|
||||
}
|
||||
else if (isJsxOpeningLikeElement(symbolToken.parent) && symbolToken.parent.tagName === symbolToken) {
|
||||
// The error wasn't for the symbolAtLocation, it was for the JSX tag itself, which needs access to e.g. `React`.
|
||||
symbol = checker.getAliasedSymbol(checker.resolveName(checker.getJsxNamespace(), symbolToken.parent.tagName, SymbolFlags.Value));
|
||||
symbol = checker.getAliasedSymbol(checker.resolveName(checker.getJsxNamespace(), symbolToken.parent.tagName, SymbolFlags.Value, /*excludeGlobals*/ false));
|
||||
symbolName = symbol.name;
|
||||
}
|
||||
else {
|
||||
@@ -867,7 +867,7 @@ namespace ts.codefix {
|
||||
return moduleSpecifierToValidIdentifier(removeFileExtension(getBaseFileName(moduleSymbol.name)), target);
|
||||
}
|
||||
|
||||
function moduleSpecifierToValidIdentifier(moduleSpecifier: string, target: ScriptTarget): string {
|
||||
export function moduleSpecifierToValidIdentifier(moduleSpecifier: string, target: ScriptTarget): string {
|
||||
let res = "";
|
||||
let lastCharWasValid = true;
|
||||
const firstCharCode = moduleSpecifier.charCodeAt(0);
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace ts.formatting {
|
||||
for (let token = SyntaxKind.FirstToken; token <= SyntaxKind.LastToken; token++) {
|
||||
allTokens.push(token);
|
||||
}
|
||||
function anyTokenExcept(token: SyntaxKind): TokenRange {
|
||||
return { tokens: allTokens.filter(t => t !== token), isSpecific: false };
|
||||
function anyTokenExcept(...tokens: SyntaxKind[]): TokenRange {
|
||||
return { tokens: allTokens.filter(t => !tokens.some(t2 => t2 === t)), isSpecific: false };
|
||||
}
|
||||
|
||||
const anyToken: TokenRange = { tokens: allTokens, isSpecific: false };
|
||||
@@ -316,6 +316,11 @@ namespace ts.formatting {
|
||||
|
||||
rule("NoSpaceBeforeComma", anyToken, SyntaxKind.CommaToken, [isNonJsxSameLineTokenContext], RuleAction.Delete),
|
||||
|
||||
// No space before and after indexer `x[]`
|
||||
rule("NoSpaceBeforeOpenBracket", anyTokenExcept(SyntaxKind.AsyncKeyword, SyntaxKind.CaseKeyword), SyntaxKind.OpenBracketToken, [isNonJsxSameLineTokenContext], RuleAction.Delete),
|
||||
rule("NoSpaceAfterCloseBracket", SyntaxKind.CloseBracketToken, anyToken, [isNonJsxSameLineTokenContext, isNotBeforeBlockInFunctionDeclarationContext], RuleAction.Delete),
|
||||
rule("SpaceAfterSemicolon", SyntaxKind.SemicolonToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.Space),
|
||||
|
||||
// Add a space between statements. All keywords except (do,else,case) has open/close parens after them.
|
||||
// So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any]
|
||||
rule(
|
||||
@@ -326,11 +331,6 @@ namespace ts.formatting {
|
||||
RuleAction.Space),
|
||||
// This low-pri rule takes care of "try {" and "finally {" in case the rule SpaceBeforeOpenBraceInControl didn't execute on FormatOnEnter.
|
||||
rule("SpaceAfterTryFinally", [SyntaxKind.TryKeyword, SyntaxKind.FinallyKeyword], SyntaxKind.OpenBraceToken, [isNonJsxSameLineTokenContext], RuleAction.Space),
|
||||
|
||||
// No space before and after indexer `x[]`
|
||||
rule("NoSpaceBeforeOpenBracket", anyTokenExcept(SyntaxKind.AsyncKeyword), SyntaxKind.OpenBracketToken, [isNonJsxSameLineTokenContext], RuleAction.Delete),
|
||||
rule("NoSpaceAfterCloseBracket", SyntaxKind.CloseBracketToken, anyToken, [isNonJsxSameLineTokenContext, isNotBeforeBlockInFunctionDeclarationContext], RuleAction.Delete),
|
||||
rule("SpaceAfterSemicolon", SyntaxKind.SemicolonToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.Space),
|
||||
];
|
||||
|
||||
return [
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace ts.Completions.PathCompletions {
|
||||
*
|
||||
* both foo.ts and foo.tsx become foo
|
||||
*/
|
||||
const foundFiles = createMap<boolean>();
|
||||
const foundFiles = createMap<true>();
|
||||
for (let filePath of files) {
|
||||
filePath = normalizePath(filePath);
|
||||
if (exclude && comparePaths(filePath, exclude, scriptPath, ignoreCase) === Comparison.EqualTo) {
|
||||
@@ -103,7 +103,7 @@ namespace ts.Completions.PathCompletions {
|
||||
|
||||
const foundFileName = includeExtensions ? getBaseFileName(filePath) : removeFileExtension(getBaseFileName(filePath));
|
||||
|
||||
if (!foundFiles.get(foundFileName)) {
|
||||
if (!foundFiles.has(foundFileName)) {
|
||||
foundFiles.set(foundFileName, true);
|
||||
}
|
||||
}
|
||||
@@ -226,8 +226,9 @@ namespace ts.Completions.PathCompletions {
|
||||
const includeGlob = normalizedSuffix ? "**/*" : "./*";
|
||||
|
||||
const matches = tryReadDirectory(host, baseDirectory, fileExtensions, /*exclude*/ undefined, [includeGlob]);
|
||||
const directories = tryGetDirectories(host, baseDirectory);
|
||||
// Trim away prefix and suffix
|
||||
return mapDefined(matches, match => {
|
||||
return mapDefined(concatenate(matches, directories), match => {
|
||||
const normalizedMatch = normalizePath(match);
|
||||
if (!endsWith(normalizedMatch, normalizedSuffix) || !startsWith(normalizedMatch, completePrefix)) {
|
||||
return;
|
||||
@@ -468,7 +469,7 @@ namespace ts.Completions.PathCompletions {
|
||||
return tryIOAndConsumeErrors(host, host.getDirectories, directoryName);
|
||||
}
|
||||
|
||||
function tryReadDirectory(host: LanguageServiceHost, path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>): string[] {
|
||||
function tryReadDirectory(host: LanguageServiceHost, path: string, extensions?: ReadonlyArray<string>, exclude?: ReadonlyArray<string>, include?: ReadonlyArray<string>): string[] | undefined {
|
||||
return tryIOAndConsumeErrors(host, host.readDirectory, path, extensions, exclude, include);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,582 @@
|
||||
/* @internal */
|
||||
namespace ts.refactor {
|
||||
const actionName = "Convert to ES6 module";
|
||||
|
||||
const convertToEs6Module: Refactor = {
|
||||
name: actionName,
|
||||
description: getLocaleSpecificMessage(Diagnostics.Convert_to_ES6_module),
|
||||
getEditsForAction,
|
||||
getAvailableActions,
|
||||
};
|
||||
|
||||
registerRefactor(convertToEs6Module);
|
||||
|
||||
function getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined {
|
||||
const { file, startPosition } = context;
|
||||
if (!isSourceFileJavaScript(file) || !file.commonJsModuleIndicator) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const node = getTokenAtPosition(file, startPosition, /*includeJsDocComment*/ false);
|
||||
return !isAtTriggerLocation(file, node) ? undefined : [
|
||||
{
|
||||
name: convertToEs6Module.name,
|
||||
description: convertToEs6Module.description,
|
||||
actions: [
|
||||
{
|
||||
description: convertToEs6Module.description,
|
||||
name: actionName,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function isAtTriggerLocation(sourceFile: SourceFile, node: Node, onSecondTry = false): boolean {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.CallExpression:
|
||||
return isAtTopLevelRequire(node as CallExpression);
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
return isExportsOrModuleExportsOrAlias(sourceFile, node as PropertyAccessExpression)
|
||||
|| isExportsOrModuleExportsOrAlias(sourceFile, (node as PropertyAccessExpression).expression);
|
||||
case SyntaxKind.VariableDeclarationList:
|
||||
const decl = (node as VariableDeclarationList).declarations[0];
|
||||
return isExportsOrModuleExportsOrAlias(sourceFile, decl.initializer);
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return isExportsOrModuleExportsOrAlias(sourceFile, (node as VariableDeclaration).initializer);
|
||||
default:
|
||||
return isExpression(node) && isExportsOrModuleExportsOrAlias(sourceFile, node)
|
||||
|| !onSecondTry && isAtTriggerLocation(sourceFile, node.parent, /*onSecondTry*/ true);
|
||||
}
|
||||
}
|
||||
|
||||
function isAtTopLevelRequire(call: CallExpression): boolean {
|
||||
if (!isRequireCall(call, /*checkArgumentIsStringLiteral*/ true)) {
|
||||
return false;
|
||||
}
|
||||
const { parent: propAccess } = call;
|
||||
const varDecl = isPropertyAccessExpression(propAccess) ? propAccess.parent : propAccess;
|
||||
if (isExpressionStatement(varDecl) && isSourceFile(varDecl.parent)) { // `require("x");` as a statement
|
||||
return true;
|
||||
}
|
||||
if (!isVariableDeclaration(varDecl)) {
|
||||
return false;
|
||||
}
|
||||
const { parent: varDeclList } = varDecl;
|
||||
if (varDeclList.kind !== SyntaxKind.VariableDeclarationList) {
|
||||
return false;
|
||||
}
|
||||
const { parent: varStatement } = varDeclList;
|
||||
return varStatement.kind === SyntaxKind.VariableStatement && varStatement.parent.kind === SyntaxKind.SourceFile;
|
||||
}
|
||||
|
||||
function getEditsForAction(context: RefactorContext, _actionName: string): RefactorEditInfo | undefined {
|
||||
Debug.assertEqual(actionName, _actionName);
|
||||
const { file, program } = context;
|
||||
Debug.assert(isSourceFileJavaScript(file));
|
||||
const edits = textChanges.ChangeTracker.with(context, changes => {
|
||||
const moduleExportsChangedToDefault = convertFileToEs6Module(file, program.getTypeChecker(), changes, program.getCompilerOptions().target);
|
||||
if (moduleExportsChangedToDefault) {
|
||||
for (const importingFile of program.getSourceFiles()) {
|
||||
fixImportOfModuleExports(importingFile, file, changes);
|
||||
}
|
||||
}
|
||||
});
|
||||
return { edits, renameFilename: undefined, renameLocation: undefined };
|
||||
}
|
||||
|
||||
function fixImportOfModuleExports(importingFile: ts.SourceFile, exportingFile: ts.SourceFile, changes: textChanges.ChangeTracker) {
|
||||
for (const moduleSpecifier of importingFile.imports) {
|
||||
const imported = getResolvedModule(importingFile, moduleSpecifier.text);
|
||||
if (!imported || imported.resolvedFileName !== exportingFile.fileName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const { parent } = moduleSpecifier;
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.ExternalModuleReference: {
|
||||
const importEq = (parent as ExternalModuleReference).parent;
|
||||
changes.replaceNode(importingFile, importEq, makeImport(importEq.name, /*namedImports*/ undefined, moduleSpecifier.text));
|
||||
break;
|
||||
}
|
||||
case SyntaxKind.CallExpression: {
|
||||
const call = parent as CallExpression;
|
||||
if (isRequireCall(call, /*checkArgumentIsStringLiteral*/ false)) {
|
||||
changes.replaceNode(importingFile, parent, createPropertyAccess(getSynthesizedDeepClone(call), "default"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @returns Whether we converted a `module.exports =` to a default export. */
|
||||
function convertFileToEs6Module(sourceFile: SourceFile, checker: TypeChecker, changes: textChanges.ChangeTracker, target: ScriptTarget): ModuleExportsChanged {
|
||||
const identifiers: Identifiers = { original: collectFreeIdentifiers(sourceFile), additional: createMap<true>() };
|
||||
const exports = collectExportRenames(sourceFile, checker, identifiers);
|
||||
convertExportsAccesses(sourceFile, exports, changes);
|
||||
let moduleExportsChangedToDefault = false;
|
||||
for (const statement of sourceFile.statements) {
|
||||
const moduleExportsChanged = convertStatement(sourceFile, statement, checker, changes, identifiers, target, exports);
|
||||
moduleExportsChangedToDefault = moduleExportsChangedToDefault || moduleExportsChanged;
|
||||
}
|
||||
return moduleExportsChangedToDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains an entry for each renamed export.
|
||||
* This is necessary because `exports.x = 0;` does not declare a local variable.
|
||||
* Converting this to `export const x = 0;` would declare a local, so we must be careful to avoid shadowing.
|
||||
* If there would be shadowing at either the declaration or at any reference to `exports.x` (now just `x`), we must convert to:
|
||||
* const _x = 0;
|
||||
* export { _x as x };
|
||||
* This conversion also must place if the exported name is not a valid identifier, e.g. `exports.class = 0;`.
|
||||
*/
|
||||
type ExportRenames = ReadonlyMap<string>;
|
||||
|
||||
function collectExportRenames(sourceFile: SourceFile, checker: TypeChecker, identifiers: Identifiers): ExportRenames {
|
||||
const res = createMap<string>();
|
||||
forEachExportReference(sourceFile, node => {
|
||||
const { text, originalKeywordKind } = node.name;
|
||||
if (!res.has(text) && (originalKeywordKind !== undefined && isNonContextualKeyword(originalKeywordKind)
|
||||
|| checker.resolveName(node.name.text, node, SymbolFlags.Value, /*excludeGlobals*/ true))) {
|
||||
// Unconditionally add an underscore in case `text` is a keyword.
|
||||
res.set(text, makeUniqueName(`_${text}`, identifiers));
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
function convertExportsAccesses(sourceFile: SourceFile, exports: ExportRenames, changes: textChanges.ChangeTracker): void {
|
||||
forEachExportReference(sourceFile, (node, isAssignmentLhs) => {
|
||||
if (isAssignmentLhs) {
|
||||
return;
|
||||
}
|
||||
const { text } = node.name;
|
||||
changes.replaceNode(sourceFile, node, createIdentifier(exports.get(text) || text));
|
||||
});
|
||||
}
|
||||
|
||||
function forEachExportReference(sourceFile: SourceFile, cb: (node: PropertyAccessExpression, isAssignmentLhs: boolean) => void): void {
|
||||
sourceFile.forEachChild(function recur(node) {
|
||||
if (isPropertyAccessExpression(node) && isExportsOrModuleExportsOrAlias(sourceFile, node.expression)) {
|
||||
const { parent } = node;
|
||||
cb(node, isBinaryExpression(parent) && parent.left === node && parent.operatorToken.kind === SyntaxKind.EqualsToken);
|
||||
}
|
||||
node.forEachChild(recur);
|
||||
});
|
||||
}
|
||||
|
||||
/** Whether `module.exports =` was changed to `export default` */
|
||||
type ModuleExportsChanged = boolean;
|
||||
|
||||
function convertStatement(sourceFile: SourceFile, statement: Statement, checker: TypeChecker, changes: textChanges.ChangeTracker, identifiers: Identifiers, target: ScriptTarget, exports: ExportRenames): ModuleExportsChanged {
|
||||
switch (statement.kind) {
|
||||
case SyntaxKind.VariableStatement:
|
||||
convertVariableStatement(sourceFile, statement as VariableStatement, changes, checker, identifiers, target);
|
||||
return false;
|
||||
case SyntaxKind.ExpressionStatement: {
|
||||
const { expression } = statement as ExpressionStatement;
|
||||
switch (expression.kind) {
|
||||
case SyntaxKind.CallExpression: {
|
||||
if (isRequireCall(expression, /*checkArgumentIsStringLiteral*/ true)) {
|
||||
// For side-effecting require() call, just make a side-effecting import.
|
||||
changes.replaceNode(sourceFile, statement, makeImport(/*name*/ undefined, /*namedImports*/ undefined, expression.arguments[0].text));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
case SyntaxKind.BinaryExpression: {
|
||||
const { left, operatorToken, right } = expression as BinaryExpression;
|
||||
return operatorToken.kind === SyntaxKind.EqualsToken && convertAssignment(sourceFile, checker, statement as ExpressionStatement, left, right, changes, exports);
|
||||
}
|
||||
}
|
||||
}
|
||||
// falls through
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function convertVariableStatement(sourceFile: SourceFile, statement: VariableStatement, changes: textChanges.ChangeTracker, checker: TypeChecker, identifiers: Identifiers, target: ScriptTarget): void {
|
||||
const { declarationList } = statement as VariableStatement;
|
||||
let foundImport = false;
|
||||
const newNodes = flatMap(declarationList.declarations, decl => {
|
||||
const { name, initializer } = decl;
|
||||
if (isExportsOrModuleExportsOrAlias(sourceFile, initializer)) {
|
||||
// `const alias = module.exports;` can be removed.
|
||||
foundImport = true;
|
||||
return [];
|
||||
}
|
||||
if (isRequireCall(initializer, /*checkArgumentIsStringLiteral*/ true)) {
|
||||
foundImport = true;
|
||||
return convertSingleImport(sourceFile, name, initializer.arguments[0].text, changes, checker, identifiers, target);
|
||||
}
|
||||
else if (isPropertyAccessExpression(initializer) && isRequireCall(initializer.expression, /*checkArgumentIsStringLiteral*/ true)) {
|
||||
foundImport = true;
|
||||
return convertPropertyAccessImport(name, initializer.name.text, initializer.expression.arguments[0].text, identifiers);
|
||||
}
|
||||
else {
|
||||
// Move it out to its own variable statement.
|
||||
return createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([decl], declarationList.flags));
|
||||
}
|
||||
});
|
||||
if (foundImport) {
|
||||
// useNonAdjustedEndPosition to ensure we don't eat the newline after the statement.
|
||||
changes.replaceNodeWithNodes(sourceFile, statement, newNodes);
|
||||
}
|
||||
}
|
||||
|
||||
/** Converts `const name = require("moduleSpecifier").propertyName` */
|
||||
function convertPropertyAccessImport(name: BindingName, propertyName: string, moduleSpecifier: string, identifiers: Identifiers): ReadonlyArray<Node> {
|
||||
switch (name.kind) {
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ArrayBindingPattern: {
|
||||
// `const [a, b] = require("c").d` --> `import { d } from "c"; const [a, b] = d;`
|
||||
const tmp = makeUniqueName(propertyName, identifiers);
|
||||
return [
|
||||
makeSingleImport(tmp, propertyName, moduleSpecifier),
|
||||
makeConst(/*modifiers*/ undefined, name, createIdentifier(tmp)),
|
||||
];
|
||||
}
|
||||
case SyntaxKind.Identifier:
|
||||
// `const a = require("b").c` --> `import { c as a } from "./b";
|
||||
return [makeSingleImport(name.text, propertyName, moduleSpecifier)];
|
||||
default:
|
||||
Debug.assertNever(name);
|
||||
}
|
||||
}
|
||||
|
||||
function convertAssignment(
|
||||
sourceFile: SourceFile,
|
||||
checker: TypeChecker,
|
||||
statement: ExpressionStatement,
|
||||
left: Expression,
|
||||
right: Expression,
|
||||
changes: textChanges.ChangeTracker,
|
||||
exports: ExportRenames,
|
||||
): ModuleExportsChanged {
|
||||
if (!isPropertyAccessExpression(left)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isExportsOrModuleExportsOrAlias(sourceFile, left)) {
|
||||
if (isExportsOrModuleExportsOrAlias(sourceFile, right)) {
|
||||
// `const alias = module.exports;` or `module.exports = alias;` can be removed.
|
||||
changes.deleteNode(sourceFile, statement);
|
||||
}
|
||||
else {
|
||||
let newNodes = isObjectLiteralExpression(right) ? tryChangeModuleExportsObject(right) : undefined;
|
||||
let changedToDefaultExport = false;
|
||||
if (!newNodes) {
|
||||
([newNodes, changedToDefaultExport] = convertModuleExportsToExportDefault(right, checker));
|
||||
}
|
||||
changes.replaceNodeWithNodes(sourceFile, statement, newNodes);
|
||||
return changedToDefaultExport;
|
||||
}
|
||||
}
|
||||
else if (isExportsOrModuleExportsOrAlias(sourceFile, left.expression)) {
|
||||
convertNamedExport(sourceFile, statement, left.name, right, changes, exports);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert `module.exports = { ... }` to individual exports..
|
||||
* We can't always do this if the module has interesting members -- then it will be a default export instead.
|
||||
*/
|
||||
function tryChangeModuleExportsObject(object: ObjectLiteralExpression): ReadonlyArray<Statement> | undefined {
|
||||
return mapAllOrFail(object.properties, prop => {
|
||||
switch (prop.kind) {
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
// TODO: Maybe we should handle this? See fourslash test `refactorConvertToEs6Module_export_object_shorthand.ts`.
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
return undefined;
|
||||
case SyntaxKind.PropertyAssignment: {
|
||||
const { name, initializer } = prop as PropertyAssignment;
|
||||
return !isIdentifier(name) ? undefined : convertExportsDotXEquals(name.text, initializer);
|
||||
}
|
||||
case SyntaxKind.MethodDeclaration: {
|
||||
const m = prop as MethodDeclaration;
|
||||
return !isIdentifier(m.name) ? undefined : functionExpressionToDeclaration(m.name.text, [createToken(SyntaxKind.ExportKeyword)], m);
|
||||
}
|
||||
default:
|
||||
Debug.assertNever(prop);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function convertNamedExport(
|
||||
sourceFile: SourceFile,
|
||||
statement: Statement,
|
||||
propertyName: Identifier,
|
||||
right: Expression,
|
||||
changes: textChanges.ChangeTracker,
|
||||
exports: ExportRenames,
|
||||
): void {
|
||||
// If "originalKeywordKind" was set, this is e.g. `exports.
|
||||
const { text } = propertyName;
|
||||
const rename = exports.get(text);
|
||||
if (rename !== undefined) {
|
||||
/*
|
||||
const _class = 0;
|
||||
export { _class as class };
|
||||
*/
|
||||
const newNodes = [
|
||||
makeConst(/*modifiers*/ undefined, rename, right),
|
||||
makeExportDeclaration([createExportSpecifier(rename, text)]),
|
||||
];
|
||||
changes.replaceNodeWithNodes(sourceFile, statement, newNodes);
|
||||
}
|
||||
else {
|
||||
changes.replaceNode(sourceFile, statement, convertExportsDotXEquals(text, right), { useNonAdjustedEndPosition: true });
|
||||
}
|
||||
}
|
||||
|
||||
function convertModuleExportsToExportDefault(exported: Expression, checker: TypeChecker): [ReadonlyArray<Statement>, ModuleExportsChanged] {
|
||||
const modifiers = [createToken(SyntaxKind.ExportKeyword), createToken(SyntaxKind.DefaultKeyword)];
|
||||
switch (exported.kind) {
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction: {
|
||||
// `module.exports = function f() {}` --> `export default function f() {}`
|
||||
const fn = exported as FunctionExpression | ArrowFunction;
|
||||
return [[functionExpressionToDeclaration(fn.name && fn.name.text, modifiers, fn)], true];
|
||||
}
|
||||
case SyntaxKind.ClassExpression: {
|
||||
// `module.exports = class C {}` --> `export default class C {}`
|
||||
const cls = exported as ClassExpression;
|
||||
return [[classExpressionToDeclaration(cls.name && cls.name.text, modifiers, cls)], true];
|
||||
}
|
||||
case SyntaxKind.CallExpression:
|
||||
if (isRequireCall(exported, /*checkArgumentIsStringLiteral*/ true)) {
|
||||
return convertReExportAll(exported.arguments[0], checker);
|
||||
}
|
||||
// falls through
|
||||
default:
|
||||
// `module.exports = 0;` --> `export default 0;`
|
||||
return [[createExportAssignment(/*decorators*/ undefined, /*modifiers*/ undefined, /*isExportEquals*/ false, exported)], true];
|
||||
}
|
||||
}
|
||||
|
||||
function convertReExportAll(reExported: StringLiteralLike, checker: TypeChecker): [ReadonlyArray<Statement>, ModuleExportsChanged] {
|
||||
// `module.exports = require("x");` ==> `export * from "x"; export { default } from "x";`
|
||||
const moduleSpecifier = reExported.text;
|
||||
const moduleSymbol = checker.getSymbolAtLocation(reExported);
|
||||
const exports = moduleSymbol ? moduleSymbol.exports : emptyUnderscoreEscapedMap;
|
||||
return exports.has("export=" as __String)
|
||||
? [[reExportDefault(moduleSpecifier)], true]
|
||||
: !exports.has("default" as __String)
|
||||
? [[reExportStar(moduleSpecifier)], false]
|
||||
// If there's some non-default export, must include both `export *` and `export default`.
|
||||
: exports.size > 1 ? [[reExportStar(moduleSpecifier), reExportDefault(moduleSpecifier)], true] : [[reExportDefault(moduleSpecifier)], true];
|
||||
}
|
||||
function reExportStar(moduleSpecifier: string): ExportDeclaration {
|
||||
return makeExportDeclaration(/*exportClause*/ undefined, moduleSpecifier);
|
||||
}
|
||||
function reExportDefault(moduleSpecifier: string): ExportDeclaration {
|
||||
return makeExportDeclaration([createExportSpecifier(/*propertyName*/ undefined, "default")], moduleSpecifier);
|
||||
}
|
||||
|
||||
function convertExportsDotXEquals(name: string | undefined, exported: Expression): Statement {
|
||||
const modifiers = [createToken(SyntaxKind.ExportKeyword)];
|
||||
switch (exported.kind) {
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
// `exports.f = function() {}` --> `export function f() {}`
|
||||
return functionExpressionToDeclaration(name, modifiers, exported as FunctionExpression | ArrowFunction);
|
||||
case SyntaxKind.ClassExpression:
|
||||
// `exports.C = class {}` --> `export class C {}`
|
||||
return classExpressionToDeclaration(name, modifiers, exported as ClassExpression);
|
||||
default:
|
||||
// `exports.x = 0;` --> `export const x = 0;`
|
||||
return makeConst(modifiers, createIdentifier(name), exported);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts `const <<name>> = require("x");`.
|
||||
* Returns nodes that will replace the variable declaration for the commonjs import.
|
||||
* May also make use `changes` to remove qualifiers at the use sites of imports, to change `mod.x` to `x`.
|
||||
*/
|
||||
function convertSingleImport(
|
||||
file: SourceFile,
|
||||
name: BindingName,
|
||||
moduleSpecifier: string,
|
||||
changes: textChanges.ChangeTracker,
|
||||
checker: TypeChecker,
|
||||
identifiers: Identifiers,
|
||||
target: ScriptTarget,
|
||||
): ReadonlyArray<Node> {
|
||||
switch (name.kind) {
|
||||
case SyntaxKind.ObjectBindingPattern: {
|
||||
const importSpecifiers = mapAllOrFail(name.elements, e =>
|
||||
e.dotDotDotToken || e.initializer || e.propertyName && !isIdentifier(e.propertyName) || !isIdentifier(e.name)
|
||||
? undefined
|
||||
: makeImportSpecifier(e.propertyName && (e.propertyName as Identifier).text, e.name.text));
|
||||
if (importSpecifiers) {
|
||||
return [makeImport(/*name*/ undefined, importSpecifiers, moduleSpecifier)];
|
||||
}
|
||||
}
|
||||
// falls through -- object destructuring has an interesting pattern and must be a variable declaration
|
||||
case SyntaxKind.ArrayBindingPattern: {
|
||||
/*
|
||||
import x from "x";
|
||||
const [a, b, c] = x;
|
||||
*/
|
||||
const tmp = makeUniqueName(codefix.moduleSpecifierToValidIdentifier(moduleSpecifier, target), identifiers);
|
||||
return [
|
||||
makeImport(createIdentifier(tmp), /*namedImports*/ undefined, moduleSpecifier),
|
||||
makeConst(/*modifiers*/ undefined, getSynthesizedDeepClone(name), createIdentifier(tmp)),
|
||||
];
|
||||
}
|
||||
case SyntaxKind.Identifier:
|
||||
return convertSingleIdentifierImport(file, name, moduleSpecifier, changes, checker, identifiers);
|
||||
default:
|
||||
Debug.assertNever(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert `import x = require("x").`
|
||||
* Also converts uses like `x.y()` to `y()` and uses a named import.
|
||||
*/
|
||||
function convertSingleIdentifierImport(file: SourceFile, name: Identifier, moduleSpecifier: string, changes: textChanges.ChangeTracker, checker: TypeChecker, identifiers: Identifiers): ReadonlyArray<Node> {
|
||||
const nameSymbol = checker.getSymbolAtLocation(name);
|
||||
// Maps from module property name to name actually used. (The same if there isn't shadowing.)
|
||||
const namedBindingsNames = createMap<string>();
|
||||
// True if there is some non-property use like `x()` or `f(x)`.
|
||||
let needDefaultImport = false;
|
||||
|
||||
for (const use of identifiers.original.get(name.text)) {
|
||||
if (checker.getSymbolAtLocation(use) !== nameSymbol || use === name) {
|
||||
// This was a use of a different symbol with the same name, due to shadowing. Ignore.
|
||||
continue;
|
||||
}
|
||||
|
||||
const { parent } = use;
|
||||
if (isPropertyAccessExpression(parent)) {
|
||||
const { expression, name: { text: propertyName } } = parent;
|
||||
Debug.assert(expression === use); // Else shouldn't have been in `collectIdentifiers`
|
||||
let idName = namedBindingsNames.get(propertyName);
|
||||
if (idName === undefined) {
|
||||
idName = makeUniqueName(propertyName, identifiers);
|
||||
namedBindingsNames.set(propertyName, idName);
|
||||
}
|
||||
changes.replaceNode(file, parent, createIdentifier(idName));
|
||||
}
|
||||
else {
|
||||
needDefaultImport = true;
|
||||
}
|
||||
}
|
||||
|
||||
const namedBindings = namedBindingsNames.size === 0 ? undefined : arrayFrom(mapIterator(namedBindingsNames.entries(), ([propertyName, idName]) =>
|
||||
createImportSpecifier(propertyName === idName ? undefined : createIdentifier(propertyName), createIdentifier(idName))));
|
||||
if (!namedBindings) {
|
||||
// If it was unused, ensure that we at least import *something*.
|
||||
needDefaultImport = true;
|
||||
}
|
||||
return [makeImport(needDefaultImport ? getSynthesizedDeepClone(name) : undefined, namedBindings, moduleSpecifier)];
|
||||
}
|
||||
|
||||
// Identifiers helpers
|
||||
|
||||
function makeUniqueName(name: string, identifiers: Identifiers): string {
|
||||
while (identifiers.original.has(name) || identifiers.additional.has(name)) {
|
||||
name = `_${name}`;
|
||||
}
|
||||
identifiers.additional.set(name, true);
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helps us create unique identifiers.
|
||||
* `original` refers to the local variable names in the original source file.
|
||||
* `additional` is any new unique identifiers we've generated. (e.g., we'll generate `_x`, then `__x`.)
|
||||
*/
|
||||
interface Identifiers {
|
||||
readonly original: FreeIdentifiers;
|
||||
// Additional identifiers we've added. Mutable!
|
||||
readonly additional: Map<true>;
|
||||
}
|
||||
|
||||
type FreeIdentifiers = ReadonlyMap<ReadonlyArray<Identifier>>;
|
||||
function collectFreeIdentifiers(file: SourceFile): FreeIdentifiers {
|
||||
const map = createMultiMap<Identifier>();
|
||||
file.forEachChild(function recur(node) {
|
||||
if (isIdentifier(node) && isFreeIdentifier(node)) {
|
||||
map.add(node.text, node);
|
||||
}
|
||||
node.forEachChild(recur);
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
function isFreeIdentifier(node: Identifier): boolean {
|
||||
const { parent } = node;
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
return (parent as PropertyAccessExpression).name !== node;
|
||||
case SyntaxKind.BindingElement:
|
||||
return (parent as BindingElement).propertyName !== node;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Node helpers
|
||||
|
||||
function functionExpressionToDeclaration(name: string | undefined, additionalModifiers: ReadonlyArray<Modifier>, fn: FunctionExpression | ArrowFunction | MethodDeclaration): FunctionDeclaration {
|
||||
return createFunctionDeclaration(
|
||||
getSynthesizedDeepClones(fn.decorators), // TODO: GH#19915 Don't think this is even legal.
|
||||
concatenate(additionalModifiers, getSynthesizedDeepClones(fn.modifiers)),
|
||||
getSynthesizedDeepClone(fn.asteriskToken),
|
||||
name,
|
||||
getSynthesizedDeepClones(fn.typeParameters),
|
||||
getSynthesizedDeepClones(fn.parameters),
|
||||
getSynthesizedDeepClone(fn.type),
|
||||
convertToFunctionBody(getSynthesizedDeepClone(fn.body)));
|
||||
}
|
||||
|
||||
function classExpressionToDeclaration(name: string | undefined, additionalModifiers: ReadonlyArray<Modifier>, cls: ClassExpression): ClassDeclaration {
|
||||
return createClassDeclaration(
|
||||
getSynthesizedDeepClones(cls.decorators), // TODO: GH#19915 Don't think this is even legal.
|
||||
concatenate(additionalModifiers, getSynthesizedDeepClones(cls.modifiers)),
|
||||
name,
|
||||
getSynthesizedDeepClones(cls.typeParameters),
|
||||
getSynthesizedDeepClones(cls.heritageClauses),
|
||||
getSynthesizedDeepClones(cls.members));
|
||||
}
|
||||
|
||||
function makeSingleImport(localName: string, propertyName: string, moduleSpecifier: string): ImportDeclaration {
|
||||
return propertyName === "default"
|
||||
? makeImport(createIdentifier(localName), /*namedImports*/ undefined, moduleSpecifier)
|
||||
: makeImport(/*name*/ undefined, [makeImportSpecifier(propertyName, localName)], moduleSpecifier);
|
||||
}
|
||||
|
||||
function makeImport(name: Identifier | undefined, namedImports: ReadonlyArray<ImportSpecifier>, moduleSpecifier: string): ImportDeclaration {
|
||||
const importClause = (name || namedImports) && createImportClause(name, namedImports && createNamedImports(namedImports));
|
||||
return createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, importClause, createLiteral(moduleSpecifier));
|
||||
}
|
||||
|
||||
function makeImportSpecifier(propertyName: string | undefined, name: string): ImportSpecifier {
|
||||
return createImportSpecifier(propertyName !== undefined && propertyName !== name ? createIdentifier(propertyName) : undefined, createIdentifier(name));
|
||||
}
|
||||
|
||||
function makeConst(modifiers: ReadonlyArray<Modifier> | undefined, name: string | BindingName, init: Expression): VariableStatement {
|
||||
return createVariableStatement(
|
||||
modifiers,
|
||||
createVariableDeclarationList(
|
||||
[createVariableDeclaration(name, /*type*/ undefined, init)],
|
||||
NodeFlags.Const));
|
||||
}
|
||||
|
||||
function makeExportDeclaration(exportSpecifiers: ExportSpecifier[] | undefined, moduleSpecifier?: string): ExportDeclaration {
|
||||
return createExportDeclaration(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
exportSpecifiers && createNamedExports(exportSpecifiers),
|
||||
moduleSpecifier === undefined ? undefined : createLiteral(moduleSpecifier));
|
||||
}
|
||||
}
|
||||
@@ -1692,7 +1692,7 @@ namespace ts.refactor.extractSymbol {
|
||||
}
|
||||
for (let i = 0; i < scopes.length; i++) {
|
||||
const scope = scopes[i];
|
||||
const resolvedSymbol = checker.resolveName(symbol.name, scope, symbol.flags);
|
||||
const resolvedSymbol = checker.resolveName(symbol.name, scope, symbol.flags, /*excludeGlobals*/ false);
|
||||
if (resolvedSymbol === symbol) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/// <reference path="annotateWithTypeFromJSDoc.ts" />
|
||||
/// <reference path="convertFunctionToEs6Class.ts" />
|
||||
/// <reference path="convertToEs6Module.ts" />
|
||||
/// <reference path="extractSymbol.ts" />
|
||||
/// <reference path="installTypesForPackage.ts" />
|
||||
/// <reference path="useDefaultImport.ts" />
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ts.refactor.installTypesForPackage {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const module = ts.getResolvedModule(file, importInfo.moduleSpecifier.text);
|
||||
const module = getResolvedModule(file, importInfo.moduleSpecifier.text);
|
||||
const resolvedFile = program.getSourceFile(module.resolvedFileName);
|
||||
if (!(resolvedFile.externalModuleIndicator && isExportAssignment(resolvedFile.externalModuleIndicator) && resolvedFile.externalModuleIndicator.isExportEquals)) {
|
||||
return undefined;
|
||||
@@ -52,7 +52,7 @@ namespace ts.refactor.installTypesForPackage {
|
||||
}
|
||||
const { importStatement, name, moduleSpecifier } = importInfo;
|
||||
const newImportClause = createImportClause(name, /*namedBindings*/ undefined);
|
||||
const newImportStatement = ts.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, newImportClause, moduleSpecifier);
|
||||
const newImportStatement = createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, newImportClause, moduleSpecifier);
|
||||
return {
|
||||
edits: textChanges.ChangeTracker.with(context, t => t.replaceNode(file, importStatement, newImportStatement)),
|
||||
renameFilename: undefined,
|
||||
|
||||
@@ -345,6 +345,11 @@ namespace ts.textChanges {
|
||||
return this.replaceWithSingle(sourceFile, startPosition, startPosition, newNode, this.getOptionsForInsertNodeBefore(before, blankLineBetween));
|
||||
}
|
||||
|
||||
public insertModifierBefore(sourceFile: SourceFile, modifier: SyntaxKind, before: Node): void {
|
||||
const pos = before.getStart(sourceFile);
|
||||
this.replaceWithSingle(sourceFile, pos, pos, createToken(modifier), { suffix: " " });
|
||||
}
|
||||
|
||||
public changeIdentifierToPropertyAccess(sourceFile: SourceFile, prefix: string, node: Identifier): void {
|
||||
const startPosition = getAdjustedStartPosition(sourceFile, node, {}, Position.Start);
|
||||
this.replaceWithSingle(sourceFile, startPosition, startPosition, createPropertyAccess(createIdentifier(prefix), ""), {});
|
||||
|
||||
@@ -1354,6 +1354,10 @@ namespace ts {
|
||||
return visited;
|
||||
}
|
||||
|
||||
export function getSynthesizedDeepClones<T extends Node>(nodes: NodeArray<T> | undefined): NodeArray<T> | undefined {
|
||||
return nodes && createNodeArray(nodes.map(getSynthesizedDeepClone), nodes.hasTrailingComma);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets EmitFlags to suppress leading and trailing trivia on the node.
|
||||
*/
|
||||
|
||||
@@ -7,11 +7,11 @@ tests/cases/compiler/abstractPropertyNegative.ts(13,7): error TS2515: Non-abstra
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(15,5): error TS1244: Abstract methods can only appear within an abstract class.
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(16,37): error TS1005: '{' expected.
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(19,3): error TS2540: Cannot assign to 'ro' because it is a constant or a read-only property.
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(25,5): error TS2416: Property 'num' in type 'WrongTypePropertyImpl' is not assignable to the same property in base type 'number'.
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(25,5): error TS2416: Property 'num' in type 'WrongTypePropertyImpl' is not assignable to the same property in base type 'WrongTypeProperty'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(31,9): error TS2416: Property 'num' in type 'WrongTypeAccessorImpl' is not assignable to the same property in base type 'number'.
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(31,9): error TS2416: Property 'num' in type 'WrongTypeAccessorImpl' is not assignable to the same property in base type 'WrongTypeAccessor'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(34,5): error TS2416: Property 'num' in type 'WrongTypeAccessorImpl2' is not assignable to the same property in base type 'number'.
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(34,5): error TS2416: Property 'num' in type 'WrongTypeAccessorImpl2' is not assignable to the same property in base type 'WrongTypeAccessor'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(38,18): error TS2676: Accessors must both be abstract or non-abstract.
|
||||
tests/cases/compiler/abstractPropertyNegative.ts(39,9): error TS2676: Accessors must both be abstract or non-abstract.
|
||||
@@ -64,7 +64,7 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors
|
||||
class WrongTypePropertyImpl extends WrongTypeProperty {
|
||||
num = "nope, wrong";
|
||||
~~~
|
||||
!!! error TS2416: Property 'num' in type 'WrongTypePropertyImpl' is not assignable to the same property in base type 'number'.
|
||||
!!! error TS2416: Property 'num' in type 'WrongTypePropertyImpl' is not assignable to the same property in base type 'WrongTypeProperty'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
}
|
||||
abstract class WrongTypeAccessor {
|
||||
@@ -73,13 +73,13 @@ tests/cases/compiler/abstractPropertyNegative.ts(41,18): error TS2676: Accessors
|
||||
class WrongTypeAccessorImpl extends WrongTypeAccessor {
|
||||
get num() { return "nope, wrong"; }
|
||||
~~~
|
||||
!!! error TS2416: Property 'num' in type 'WrongTypeAccessorImpl' is not assignable to the same property in base type 'number'.
|
||||
!!! error TS2416: Property 'num' in type 'WrongTypeAccessorImpl' is not assignable to the same property in base type 'WrongTypeAccessor'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
}
|
||||
class WrongTypeAccessorImpl2 extends WrongTypeAccessor {
|
||||
num = "nope, wrong";
|
||||
~~~
|
||||
!!! error TS2416: Property 'num' in type 'WrongTypeAccessorImpl2' is not assignable to the same property in base type 'number'.
|
||||
!!! error TS2416: Property 'num' in type 'WrongTypeAccessorImpl2' is not assignable to the same property in base type 'WrongTypeAccessor'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
tests/cases/compiler/anyMappedTypesError.ts(1,12): error TS7039: Mapped object type implicitly has an 'any' template type.
|
||||
|
||||
|
||||
==== tests/cases/compiler/anyMappedTypesError.ts (1 errors) ====
|
||||
type Foo = {[P in "bar"]};
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS7039: Mapped object type implicitly has an 'any' template type.
|
||||
@@ -0,0 +1,4 @@
|
||||
//// [anyMappedTypesError.ts]
|
||||
type Foo = {[P in "bar"]};
|
||||
|
||||
//// [anyMappedTypesError.js]
|
||||
@@ -0,0 +1,5 @@
|
||||
=== tests/cases/compiler/anyMappedTypesError.ts ===
|
||||
type Foo = {[P in "bar"]};
|
||||
>Foo : Symbol(Foo, Decl(anyMappedTypesError.ts, 0, 0))
|
||||
>P : Symbol(P, Decl(anyMappedTypesError.ts, 0, 13))
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
=== tests/cases/compiler/anyMappedTypesError.ts ===
|
||||
type Foo = {[P in "bar"]};
|
||||
>Foo : Foo
|
||||
>P : P
|
||||
|
||||
+3
-1
@@ -901,6 +901,7 @@ declare namespace ts {
|
||||
kind: SyntaxKind.ArrowFunction;
|
||||
equalsGreaterThanToken: EqualsGreaterThanToken;
|
||||
body: ConciseBody;
|
||||
name: never;
|
||||
}
|
||||
interface LiteralLikeNode extends Node {
|
||||
text: string;
|
||||
@@ -1362,6 +1363,7 @@ declare namespace ts {
|
||||
interface ExportDeclaration extends DeclarationStatement {
|
||||
kind: SyntaxKind.ExportDeclaration;
|
||||
parent?: SourceFile | ModuleBlock;
|
||||
/** Will not be assigned in the case of `export * from "foo";` */
|
||||
exportClause?: NamedExports;
|
||||
/** If this is not a StringLiteral it will be a grammar error. */
|
||||
moduleSpecifier?: Expression;
|
||||
@@ -3288,7 +3290,7 @@ declare namespace ts {
|
||||
declare namespace ts {
|
||||
function createNodeArray<T extends Node>(elements?: ReadonlyArray<T>, hasTrailingComma?: boolean): NodeArray<T>;
|
||||
/** If a node is passed, creates a string literal whose source text is read from a source node during emit. */
|
||||
function createLiteral(value: string | StringLiteral | NumericLiteral | Identifier): StringLiteral;
|
||||
function createLiteral(value: string | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | Identifier): StringLiteral;
|
||||
function createLiteral(value: number): NumericLiteral;
|
||||
function createLiteral(value: boolean): BooleanLiteral;
|
||||
function createLiteral(value: string | number | boolean): PrimaryExpression;
|
||||
|
||||
+3
-1
@@ -901,6 +901,7 @@ declare namespace ts {
|
||||
kind: SyntaxKind.ArrowFunction;
|
||||
equalsGreaterThanToken: EqualsGreaterThanToken;
|
||||
body: ConciseBody;
|
||||
name: never;
|
||||
}
|
||||
interface LiteralLikeNode extends Node {
|
||||
text: string;
|
||||
@@ -1362,6 +1363,7 @@ declare namespace ts {
|
||||
interface ExportDeclaration extends DeclarationStatement {
|
||||
kind: SyntaxKind.ExportDeclaration;
|
||||
parent?: SourceFile | ModuleBlock;
|
||||
/** Will not be assigned in the case of `export * from "foo";` */
|
||||
exportClause?: NamedExports;
|
||||
/** If this is not a StringLiteral it will be a grammar error. */
|
||||
moduleSpecifier?: Expression;
|
||||
@@ -3235,7 +3237,7 @@ declare namespace ts {
|
||||
declare namespace ts {
|
||||
function createNodeArray<T extends Node>(elements?: ReadonlyArray<T>, hasTrailingComma?: boolean): NodeArray<T>;
|
||||
/** If a node is passed, creates a string literal whose source text is read from a source node during emit. */
|
||||
function createLiteral(value: string | StringLiteral | NumericLiteral | Identifier): StringLiteral;
|
||||
function createLiteral(value: string | StringLiteral | NoSubstitutionTemplateLiteral | NumericLiteral | Identifier): StringLiteral;
|
||||
function createLiteral(value: number): NumericLiteral;
|
||||
function createLiteral(value: boolean): BooleanLiteral;
|
||||
function createLiteral(value: string | number | boolean): PrimaryExpression;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'string'.
|
||||
tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtyping.ts(10,5): error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'Base<string>'.
|
||||
Type 'String' is not assignable to type 'string'.
|
||||
'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.
|
||||
|
||||
@@ -15,7 +15,7 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSubtypi
|
||||
class Derived<U> extends Base<string> { // error
|
||||
x: String;
|
||||
~
|
||||
!!! error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'string'.
|
||||
!!! error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'Base<string>'.
|
||||
!!! error TS2416: Type 'String' is not assignable to type 'string'.
|
||||
!!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts(10,5): error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'string'.
|
||||
tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSupertype.ts(10,5): error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'Base'.
|
||||
Type 'U' is not assignable to type 'string'.
|
||||
Type 'String' is not assignable to type 'string'.
|
||||
'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.
|
||||
@@ -16,7 +16,7 @@ tests/cases/conformance/types/typeRelationships/apparentType/apparentTypeSuperty
|
||||
class Derived<U extends String> extends Base { // error
|
||||
x: U;
|
||||
~
|
||||
!!! error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'string'.
|
||||
!!! error TS2416: Property 'x' in type 'Derived<U>' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'string'.
|
||||
!!! error TS2416: Type 'String' is not assignable to type 'string'.
|
||||
!!! error TS2416: 'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2416: Property 'n' in type 'Derived' is not assignable to the same property in base type 'string | Base'.
|
||||
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2416: Property 'n' in type 'Derived' is not assignable to the same property in base type 'Base'.
|
||||
Type 'string | Derived' is not assignable to type 'string | Base'.
|
||||
Type 'Derived' is not assignable to type 'string | Base'.
|
||||
Type 'Derived' is not assignable to type 'Base'.
|
||||
@@ -6,11 +6,11 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2416: Prop
|
||||
Type 'string | Derived' is not assignable to type 'string | Base'.
|
||||
Type 'Derived' is not assignable to type 'string | Base'.
|
||||
Type 'Derived' is not assignable to type 'Base'.
|
||||
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(9,5): error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type '() => number'.
|
||||
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(9,5): error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'.
|
||||
Type '() => string | number' is not assignable to type '() => number'.
|
||||
Type 'string | number' is not assignable to type 'number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(14,5): error TS2416: Property 'n' in type 'DerivedInterface' is not assignable to the same property in base type 'string | Base'.
|
||||
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(14,5): error TS2416: Property 'n' in type 'DerivedInterface' is not assignable to the same property in base type 'Base'.
|
||||
Type 'string | DerivedInterface' is not assignable to type 'string | Base'.
|
||||
Type 'DerivedInterface' is not assignable to type 'string | Base'.
|
||||
Type 'DerivedInterface' is not assignable to type 'Base'.
|
||||
@@ -18,7 +18,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(14,5): error TS2416: Pro
|
||||
Type 'string | DerivedInterface' is not assignable to type 'string | Base'.
|
||||
Type 'DerivedInterface' is not assignable to type 'string | Base'.
|
||||
Type 'DerivedInterface' is not assignable to type 'Base'.
|
||||
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Property 'fn' in type 'DerivedInterface' is not assignable to the same property in base type '() => number'.
|
||||
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Property 'fn' in type 'DerivedInterface' is not assignable to the same property in base type 'Base'.
|
||||
Type '() => string | number' is not assignable to type '() => number'.
|
||||
Type 'string | number' is not assignable to type 'number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
@@ -34,7 +34,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro
|
||||
class Derived extends Base {
|
||||
n: Derived | string;
|
||||
~
|
||||
!!! error TS2416: Property 'n' in type 'Derived' is not assignable to the same property in base type 'string | Base'.
|
||||
!!! error TS2416: Property 'n' in type 'Derived' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Type 'string | Derived' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: Type 'Derived' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: Type 'Derived' is not assignable to type 'Base'.
|
||||
@@ -44,7 +44,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro
|
||||
!!! error TS2416: Type 'Derived' is not assignable to type 'Base'.
|
||||
fn() {
|
||||
~~
|
||||
!!! error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type '() => number'.
|
||||
!!! error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Type '() => string | number' is not assignable to type '() => number'.
|
||||
!!! error TS2416: Type 'string | number' is not assignable to type 'number'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
@@ -54,7 +54,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro
|
||||
class DerivedInterface implements Base {
|
||||
n: DerivedInterface | string;
|
||||
~
|
||||
!!! error TS2416: Property 'n' in type 'DerivedInterface' is not assignable to the same property in base type 'string | Base'.
|
||||
!!! error TS2416: Property 'n' in type 'DerivedInterface' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Type 'string | DerivedInterface' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: Type 'DerivedInterface' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: Type 'DerivedInterface' is not assignable to type 'Base'.
|
||||
@@ -64,7 +64,7 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro
|
||||
!!! error TS2416: Type 'DerivedInterface' is not assignable to type 'Base'.
|
||||
fn() {
|
||||
~~
|
||||
!!! error TS2416: Property 'fn' in type 'DerivedInterface' is not assignable to the same property in base type '() => number'.
|
||||
!!! error TS2416: Property 'fn' in type 'DerivedInterface' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Type '() => string | number' is not assignable to type '() => number'.
|
||||
!!! error TS2416: Type 'string | number' is not assignable to type 'number'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type '{ bar: string; }'.
|
||||
tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/classIsSubtypeOfBaseType.ts(12,5): error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type 'Base<{ bar: string; }>'.
|
||||
Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'.
|
||||
Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'.
|
||||
|
||||
@@ -17,7 +17,7 @@ tests/cases/conformance/classes/classDeclarations/classHeritageSpecification/cla
|
||||
class Derived2 extends Base<{ bar: string; }> {
|
||||
foo: {
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type '{ bar: string; }'.
|
||||
!!! error TS2416: Property 'foo' in type 'Derived2' is not assignable to the same property in base type 'Base<{ bar: string; }>'.
|
||||
!!! error TS2416: Type '{ bar?: string; }' is not assignable to type '{ bar: string; }'.
|
||||
!!! error TS2416: Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'.
|
||||
bar?: string; // error
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor.ts(2,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor.ts(11,5): error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'number'.
|
||||
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor.ts(11,5): error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'Base'.
|
||||
Type '() => number' is not assignable to type 'number'.
|
||||
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFunctionOverridesBaseClassAccessor.ts(11,5): error TS2426: Class 'Base' defines instance member accessor 'x', but extended class 'Derived' defines it as instance member function.
|
||||
|
||||
@@ -22,7 +22,7 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassFun
|
||||
class Derived extends Base {
|
||||
x() {
|
||||
~
|
||||
!!! error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'number'.
|
||||
!!! error TS2416: Property 'x' in type 'Derived' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Type '() => number' is not assignable to type 'number'.
|
||||
~
|
||||
!!! error TS2426: Class 'Base' defines instance member accessor 'x', but extended class 'Derived' defines it as instance member function.
|
||||
|
||||
@@ -35,7 +35,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(46,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(47,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(56,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(57,5): error TS2416: Property 'd4' in type 'C4' is not assignable to the same property in base type '({ x, y, z }?: { x: any; y: any; z: any; }) => any'.
|
||||
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(57,5): error TS2416: Property 'd4' in type 'C4' is not assignable to the same property in base type 'F2'.
|
||||
Type '({ x, y, c }: { x: any; y: any; c: any; }) => void' is not assignable to type '({ x, y, z }?: { x: any; y: any; z: any; }) => any'.
|
||||
Types of parameters '__0' and '__0' are incompatible.
|
||||
Type '{ x: any; y: any; z: any; }' is not assignable to type '{ x: any; y: any; c: any; }'.
|
||||
@@ -159,7 +159,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
|
||||
!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
|
||||
d4({x, y, c}) { }
|
||||
~~
|
||||
!!! error TS2416: Property 'd4' in type 'C4' is not assignable to the same property in base type '({ x, y, z }?: { x: any; y: any; z: any; }) => any'.
|
||||
!!! error TS2416: Property 'd4' in type 'C4' is not assignable to the same property in base type 'F2'.
|
||||
!!! error TS2416: Type '({ x, y, c }: { x: any; y: any; c: any; }) => void' is not assignable to type '({ x, y, z }?: { x: any; y: any; z: any; }) => any'.
|
||||
!!! error TS2416: Types of parameters '__0' and '__0' are incompatible.
|
||||
!!! error TS2416: Type '{ x: any; y: any; z: any; }' is not assignable to type '{ x: any; y: any; c: any; }'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/elaboratedErrors.ts(11,3): error TS2416: Property 'read' in type 'WorkerFS' is not assignable to the same property in base type 'number'.
|
||||
tests/cases/compiler/elaboratedErrors.ts(11,3): error TS2416: Property 'read' in type 'WorkerFS' is not assignable to the same property in base type 'FileSystem'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/elaboratedErrors.ts(20,1): error TS2322: Type 'Beta' is not assignable to type 'Alpha'.
|
||||
Property 'x' is missing in type 'Beta'.
|
||||
@@ -21,7 +21,7 @@ tests/cases/compiler/elaboratedErrors.ts(25,1): error TS2322: Type 'Alpha' is no
|
||||
class WorkerFS implements FileSystem {
|
||||
read: string;
|
||||
~~~~
|
||||
!!! error TS2416: Property 'read' in type 'WorkerFS' is not assignable to the same property in base type 'number'.
|
||||
!!! error TS2416: Property 'read' in type 'WorkerFS' is not assignable to the same property in base type 'FileSystem'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/genericImplements.ts(9,5): error TS2416: Property 'f' in type 'X' is not assignable to the same property in base type '<T extends A>() => T'.
|
||||
tests/cases/compiler/genericImplements.ts(9,5): error TS2416: Property 'f' in type 'X' is not assignable to the same property in base type 'I'.
|
||||
Type '<T extends B>() => T' is not assignable to type '<T extends A>() => T'.
|
||||
Type 'B' is not assignable to type 'T'.
|
||||
|
||||
@@ -14,7 +14,7 @@ tests/cases/compiler/genericImplements.ts(9,5): error TS2416: Property 'f' in ty
|
||||
class X implements I {
|
||||
f<T extends B>(): T { return undefined; }
|
||||
~
|
||||
!!! error TS2416: Property 'f' in type 'X' is not assignable to the same property in base type '<T extends A>() => T'.
|
||||
!!! error TS2416: Property 'f' in type 'X' is not assignable to the same property in base type 'I'.
|
||||
!!! error TS2416: Type '<T extends B>() => T' is not assignable to type '<T extends A>() => T'.
|
||||
!!! error TS2416: Type 'B' is not assignable to type 'T'.
|
||||
} // { f: () => { b; } }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
tests/cases/compiler/genericSpecializations1.ts(6,5): error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
tests/cases/compiler/genericSpecializations1.ts(6,5): error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type 'IFoo<number>'.
|
||||
Type '(x: string) => string' is not assignable to type '<T>(x: T) => T'.
|
||||
Types of parameters 'x' and 'x' are incompatible.
|
||||
Type 'T' is not assignable to type 'string'.
|
||||
tests/cases/compiler/genericSpecializations1.ts(10,5): error TS2416: Property 'foo' in type 'StringFoo2' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
tests/cases/compiler/genericSpecializations1.ts(10,5): error TS2416: Property 'foo' in type 'StringFoo2' is not assignable to the same property in base type 'IFoo<string>'.
|
||||
Type '(x: string) => string' is not assignable to type '<T>(x: T) => T'.
|
||||
Types of parameters 'x' and 'x' are incompatible.
|
||||
Type 'T' is not assignable to type 'string'.
|
||||
@@ -16,7 +16,7 @@ tests/cases/compiler/genericSpecializations1.ts(10,5): error TS2416: Property 'f
|
||||
class IntFooBad implements IFoo<number> {
|
||||
foo(x: string): string { return null; }
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type 'IFoo<number>'.
|
||||
!!! error TS2416: Type '(x: string) => string' is not assignable to type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Types of parameters 'x' and 'x' are incompatible.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'string'.
|
||||
@@ -25,7 +25,7 @@ tests/cases/compiler/genericSpecializations1.ts(10,5): error TS2416: Property 'f
|
||||
class StringFoo2 implements IFoo<string> {
|
||||
foo(x: string): string { return null; }
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'StringFoo2' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Property 'foo' in type 'StringFoo2' is not assignable to the same property in base type 'IFoo<string>'.
|
||||
!!! error TS2416: Type '(x: string) => string' is not assignable to type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Types of parameters 'x' and 'x' are incompatible.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'string'.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
tests/cases/compiler/genericSpecializations2.ts(8,5): error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
tests/cases/compiler/genericSpecializations2.ts(8,5): error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type 'IFoo<number>'.
|
||||
Type '<string>(x: string) => string' is not assignable to type '<T>(x: T) => T'.
|
||||
Types of parameters 'x' and 'x' are incompatible.
|
||||
Type 'T' is not assignable to type 'string'.
|
||||
tests/cases/compiler/genericSpecializations2.ts(8,9): error TS2368: Type parameter name cannot be 'string'.
|
||||
tests/cases/compiler/genericSpecializations2.ts(12,5): error TS2416: Property 'foo' in type 'StringFoo2' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
tests/cases/compiler/genericSpecializations2.ts(12,5): error TS2416: Property 'foo' in type 'StringFoo2' is not assignable to the same property in base type 'IFoo<string>'.
|
||||
Type '<string>(x: string) => string' is not assignable to type '<T>(x: T) => T'.
|
||||
Types of parameters 'x' and 'x' are incompatible.
|
||||
Type 'T' is not assignable to type 'string'.
|
||||
@@ -20,7 +20,7 @@ tests/cases/compiler/genericSpecializations2.ts(12,9): error TS2368: Type parame
|
||||
class IntFooBad implements IFoo<number> {
|
||||
foo<string>(x: string): string { return null; }
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type 'IFoo<number>'.
|
||||
!!! error TS2416: Type '<string>(x: string) => string' is not assignable to type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Types of parameters 'x' and 'x' are incompatible.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'string'.
|
||||
@@ -31,7 +31,7 @@ tests/cases/compiler/genericSpecializations2.ts(12,9): error TS2368: Type parame
|
||||
class StringFoo2 implements IFoo<string> {
|
||||
foo<string>(x: string): string { return null; }
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'StringFoo2' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Property 'foo' in type 'StringFoo2' is not assignable to the same property in base type 'IFoo<string>'.
|
||||
!!! error TS2416: Type '<string>(x: string) => string' is not assignable to type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Types of parameters 'x' and 'x' are incompatible.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'string'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/genericSpecializations3.ts(9,5): error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type '(x: number) => number'.
|
||||
tests/cases/compiler/genericSpecializations3.ts(9,5): error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type 'IFoo<number>'.
|
||||
Type '(x: string) => string' is not assignable to type '(x: number) => number'.
|
||||
Types of parameters 'x' and 'x' are incompatible.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
@@ -25,7 +25,7 @@ tests/cases/compiler/genericSpecializations3.ts(29,1): error TS2322: Type 'IntFo
|
||||
class IntFooBad implements IFoo<number> { // error
|
||||
foo(x: string): string { return null; }
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type '(x: number) => number'.
|
||||
!!! error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type 'IFoo<number>'.
|
||||
!!! error TS2416: Type '(x: string) => string' is not assignable to type '(x: number) => number'.
|
||||
!!! error TS2416: Types of parameters 'x' and 'x' are incompatible.
|
||||
!!! error TS2416: Type 'number' is not assignable to type 'string'.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/genericTypeWithNonGenericBaseMisMatch.ts(5,2): error TS2416: Property 'f' in type 'X<T>' is not assignable to the same property in base type '(a: { a: number; }) => void'.
|
||||
tests/cases/compiler/genericTypeWithNonGenericBaseMisMatch.ts(5,2): error TS2416: Property 'f' in type 'X<T>' is not assignable to the same property in base type 'I'.
|
||||
Type '(a: T) => void' is not assignable to type '(a: { a: number; }) => void'.
|
||||
Types of parameters 'a' and 'a' are incompatible.
|
||||
Type '{ a: number; }' is not assignable to type 'T'.
|
||||
@@ -18,7 +18,7 @@ tests/cases/compiler/genericTypeWithNonGenericBaseMisMatch.ts(8,5): error TS2322
|
||||
class X<T extends { a: string }> implements I {
|
||||
f(a: T): void { }
|
||||
~
|
||||
!!! error TS2416: Property 'f' in type 'X<T>' is not assignable to the same property in base type '(a: { a: number; }) => void'.
|
||||
!!! error TS2416: Property 'f' in type 'X<T>' is not assignable to the same property in base type 'I'.
|
||||
!!! error TS2416: Type '(a: T) => void' is not assignable to type '(a: { a: number; }) => void'.
|
||||
!!! error TS2416: Types of parameters 'a' and 'a' are incompatible.
|
||||
!!! error TS2416: Type '{ a: number; }' is not assignable to type 'T'.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
tests/cases/compiler/implementGenericWithMismatchedTypes.ts(8,5): error TS2416: Property 'foo' in type 'C<T>' is not assignable to the same property in base type '(x: T) => T'.
|
||||
tests/cases/compiler/implementGenericWithMismatchedTypes.ts(8,5): error TS2416: Property 'foo' in type 'C<T>' is not assignable to the same property in base type 'IFoo<T>'.
|
||||
Type '(x: string) => number' is not assignable to type '(x: T) => T'.
|
||||
Types of parameters 'x' and 'x' are incompatible.
|
||||
Type 'T' is not assignable to type 'string'.
|
||||
tests/cases/compiler/implementGenericWithMismatchedTypes.ts(17,5): error TS2416: Property 'foo' in type 'C2<T>' is not assignable to the same property in base type '(x: T) => T'.
|
||||
tests/cases/compiler/implementGenericWithMismatchedTypes.ts(17,5): error TS2416: Property 'foo' in type 'C2<T>' is not assignable to the same property in base type 'IFoo2<T>'.
|
||||
Type '<Tstring>(x: Tstring) => number' is not assignable to type '(x: T) => T'.
|
||||
Type 'number' is not assignable to type 'T'.
|
||||
|
||||
@@ -17,7 +17,7 @@ tests/cases/compiler/implementGenericWithMismatchedTypes.ts(17,5): error TS2416:
|
||||
class C<T> implements IFoo<T> { // error
|
||||
foo(x: string): number {
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'C<T>' is not assignable to the same property in base type '(x: T) => T'.
|
||||
!!! error TS2416: Property 'foo' in type 'C<T>' is not assignable to the same property in base type 'IFoo<T>'.
|
||||
!!! error TS2416: Type '(x: string) => number' is not assignable to type '(x: T) => T'.
|
||||
!!! error TS2416: Types of parameters 'x' and 'x' are incompatible.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'string'.
|
||||
@@ -31,7 +31,7 @@ tests/cases/compiler/implementGenericWithMismatchedTypes.ts(17,5): error TS2416:
|
||||
class C2<T> implements IFoo2<T> { // error
|
||||
foo<Tstring>(x: Tstring): number {
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'C2<T>' is not assignable to the same property in base type '(x: T) => T'.
|
||||
!!! error TS2416: Property 'foo' in type 'C2<T>' is not assignable to the same property in base type 'IFoo2<T>'.
|
||||
!!! error TS2416: Type '<Tstring>(x: Tstring) => number' is not assignable to type '(x: T) => T'.
|
||||
!!! error TS2416: Type 'number' is not assignable to type 'T'.
|
||||
return null;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/implementsIncorrectlyNoAssertion.ts(9,5): error TS2416: Property 'x' in type 'Baz' is not assignable to the same property in base type 'string'.
|
||||
tests/cases/compiler/implementsIncorrectlyNoAssertion.ts(9,5): error TS2416: Property 'x' in type 'Baz' is not assignable to the same property in base type 'Foo & Bar'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ tests/cases/compiler/implementsIncorrectlyNoAssertion.ts(9,5): error TS2416: Pro
|
||||
class Baz implements Wrapper {
|
||||
x: number;
|
||||
~
|
||||
!!! error TS2416: Property 'x' in type 'Baz' is not assignable to the same property in base type 'string'.
|
||||
!!! error TS2416: Property 'x' in type 'Baz' is not assignable to the same property in base type 'Foo & Bar'.
|
||||
!!! error TS2416: Type 'number' is not assignable to type 'string'.
|
||||
y: string;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
tests/cases/compiler/incompatibleTypes.ts(6,12): error TS2416: Property 'p1' in type 'C1' is not assignable to the same property in base type '() => number'.
|
||||
tests/cases/compiler/incompatibleTypes.ts(6,12): error TS2416: Property 'p1' in type 'C1' is not assignable to the same property in base type 'IFoo1'.
|
||||
Type '() => string' is not assignable to type '() => number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/incompatibleTypes.ts(16,12): error TS2416: Property 'p1' in type 'C2' is not assignable to the same property in base type '(s: string) => number'.
|
||||
tests/cases/compiler/incompatibleTypes.ts(16,12): error TS2416: Property 'p1' in type 'C2' is not assignable to the same property in base type 'IFoo2'.
|
||||
Type '(n: number) => number' is not assignable to type '(s: string) => number'.
|
||||
Types of parameters 'n' and 's' are incompatible.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/incompatibleTypes.ts(26,12): error TS2416: Property 'p1' in type 'C3' is not assignable to the same property in base type 'string'.
|
||||
tests/cases/compiler/incompatibleTypes.ts(26,12): error TS2416: Property 'p1' in type 'C3' is not assignable to the same property in base type 'IFoo3'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/compiler/incompatibleTypes.ts(34,12): error TS2416: Property 'p1' in type 'C4' is not assignable to the same property in base type '{ a: { a: string; }; b: string; }'.
|
||||
tests/cases/compiler/incompatibleTypes.ts(34,12): error TS2416: Property 'p1' in type 'C4' is not assignable to the same property in base type 'IFoo4'.
|
||||
Type '{ c: { b: string; }; d: string; }' is not assignable to type '{ a: { a: string; }; b: string; }'.
|
||||
Property 'a' is missing in type '{ c: { b: string; }; d: string; }'.
|
||||
tests/cases/compiler/incompatibleTypes.ts(42,5): error TS2345: Argument of type 'C1' is not assignable to parameter of type 'IFoo2'.
|
||||
@@ -30,7 +30,7 @@ tests/cases/compiler/incompatibleTypes.ts(74,5): error TS2322: Type '(a: any) =>
|
||||
class C1 implements IFoo1 { // incompatible on the return type
|
||||
public p1() {
|
||||
~~
|
||||
!!! error TS2416: Property 'p1' in type 'C1' is not assignable to the same property in base type '() => number'.
|
||||
!!! error TS2416: Property 'p1' in type 'C1' is not assignable to the same property in base type 'IFoo1'.
|
||||
!!! error TS2416: Type '() => string' is not assignable to type '() => number'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
return "s";
|
||||
@@ -44,7 +44,7 @@ tests/cases/compiler/incompatibleTypes.ts(74,5): error TS2322: Type '(a: any) =>
|
||||
class C2 implements IFoo2 { // incompatible on the param type
|
||||
public p1(n:number) {
|
||||
~~
|
||||
!!! error TS2416: Property 'p1' in type 'C2' is not assignable to the same property in base type '(s: string) => number'.
|
||||
!!! error TS2416: Property 'p1' in type 'C2' is not assignable to the same property in base type 'IFoo2'.
|
||||
!!! error TS2416: Type '(n: number) => number' is not assignable to type '(s: string) => number'.
|
||||
!!! error TS2416: Types of parameters 'n' and 's' are incompatible.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
@@ -59,7 +59,7 @@ tests/cases/compiler/incompatibleTypes.ts(74,5): error TS2322: Type '(a: any) =>
|
||||
class C3 implements IFoo3 { // incompatible on the property type
|
||||
public p1: number;
|
||||
~~
|
||||
!!! error TS2416: Property 'p1' in type 'C3' is not assignable to the same property in base type 'string'.
|
||||
!!! error TS2416: Property 'p1' in type 'C3' is not assignable to the same property in base type 'IFoo3'.
|
||||
!!! error TS2416: Type 'number' is not assignable to type 'string'.
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ tests/cases/compiler/incompatibleTypes.ts(74,5): error TS2322: Type '(a: any) =>
|
||||
class C4 implements IFoo4 { // incompatible on the property type
|
||||
public p1: { c: { b: string; }; d: string; };
|
||||
~~
|
||||
!!! error TS2416: Property 'p1' in type 'C4' is not assignable to the same property in base type '{ a: { a: string; }; b: string; }'.
|
||||
!!! error TS2416: Property 'p1' in type 'C4' is not assignable to the same property in base type 'IFoo4'.
|
||||
!!! error TS2416: Type '{ c: { b: string; }; d: string; }' is not assignable to type '{ a: { a: string; }; b: string; }'.
|
||||
!!! error TS2416: Property 'a' is missing in type '{ c: { b: string; }; d: string; }'.
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
tests/cases/compiler/inheritance.ts(31,12): error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function.
|
||||
tests/cases/compiler/inheritance.ts(32,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type '() => number'.
|
||||
tests/cases/compiler/inheritance.ts(32,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'.
|
||||
Type '(n: number) => number' is not assignable to type '() => number'.
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ tests/cases/compiler/inheritance.ts(32,12): error TS2416: Property 'g' in type '
|
||||
!!! error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function.
|
||||
public g(n: number) { return 0; }
|
||||
~
|
||||
!!! error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type '() => number'.
|
||||
!!! error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'.
|
||||
!!! error TS2416: Type '(n: number) => number' is not assignable to type '() => number'.
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
tests/cases/compiler/inheritanceMemberAccessorOverridingMethod.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/compiler/inheritanceMemberAccessorOverridingMethod.ts(8,9): error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type '() => string'.
|
||||
tests/cases/compiler/inheritanceMemberAccessorOverridingMethod.ts(8,9): error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type 'a'.
|
||||
Type 'string' is not assignable to type '() => string'.
|
||||
tests/cases/compiler/inheritanceMemberAccessorOverridingMethod.ts(8,9): error TS2423: Class 'a' defines instance member function 'x', but extended class 'b' defines it as instance member accessor.
|
||||
tests/cases/compiler/inheritanceMemberAccessorOverridingMethod.ts(11,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/compiler/inheritanceMemberAccessorOverridingMethod.ts(11,9): error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type '() => string'.
|
||||
tests/cases/compiler/inheritanceMemberAccessorOverridingMethod.ts(11,9): error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type 'a'.
|
||||
Type 'string' is not assignable to type '() => string'.
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ tests/cases/compiler/inheritanceMemberAccessorOverridingMethod.ts(11,9): error T
|
||||
~
|
||||
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
~
|
||||
!!! error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type '() => string'.
|
||||
!!! error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type 'a'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type '() => string'.
|
||||
~
|
||||
!!! error TS2423: Class 'a' defines instance member function 'x', but extended class 'b' defines it as instance member accessor.
|
||||
@@ -29,7 +29,7 @@ tests/cases/compiler/inheritanceMemberAccessorOverridingMethod.ts(11,9): error T
|
||||
~
|
||||
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
~
|
||||
!!! error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type '() => string'.
|
||||
!!! error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type 'a'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type '() => string'.
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
tests/cases/compiler/inheritanceMemberFuncOverridingAccessor.ts(2,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/compiler/inheritanceMemberFuncOverridingAccessor.ts(5,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
|
||||
tests/cases/compiler/inheritanceMemberFuncOverridingAccessor.ts(11,5): error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type 'string'.
|
||||
tests/cases/compiler/inheritanceMemberFuncOverridingAccessor.ts(11,5): error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type 'a'.
|
||||
Type '() => string' is not assignable to type 'string'.
|
||||
tests/cases/compiler/inheritanceMemberFuncOverridingAccessor.ts(11,5): error TS2426: Class 'a' defines instance member accessor 'x', but extended class 'b' defines it as instance member function.
|
||||
|
||||
@@ -22,7 +22,7 @@ tests/cases/compiler/inheritanceMemberFuncOverridingAccessor.ts(11,5): error TS2
|
||||
class b extends a {
|
||||
x() {
|
||||
~
|
||||
!!! error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type 'string'.
|
||||
!!! error TS2416: Property 'x' in type 'b' is not assignable to the same property in base type 'a'.
|
||||
!!! error TS2416: Type '() => string' is not assignable to type 'string'.
|
||||
~
|
||||
!!! error TS2426: Class 'a' defines instance member accessor 'x', but extended class 'b' defines it as instance member function.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2416: Property 'x' in type 'C2<T>' is not assignable to the same property in base type 'C2<T>'.
|
||||
tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2416: Property 'x' in type 'C2<T>' is not assignable to the same property in base type 'C1<T>'.
|
||||
Type 'string' is not assignable to type 'C2<T>'.
|
||||
|
||||
|
||||
@@ -10,6 +10,6 @@ tests/cases/compiler/instanceSubtypeCheck2.ts(6,5): error TS2416: Property 'x' i
|
||||
class C2<T> extends C1<T> {
|
||||
x: string
|
||||
~
|
||||
!!! error TS2416: Property 'x' in type 'C2<T>' is not assignable to the same property in base type 'C2<T>'.
|
||||
!!! error TS2416: Property 'x' in type 'C2<T>' is not assignable to the same property in base type 'C1<T>'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'C2<T>'.
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
tests/cases/compiler/interfaceDeclaration3.ts(7,16): error TS2416: Property 'item' in type 'C1' is not assignable to the same property in base type 'string'.
|
||||
tests/cases/compiler/interfaceDeclaration3.ts(7,16): error TS2416: Property 'item' in type 'C1' is not assignable to the same property in base type 'I1'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/compiler/interfaceDeclaration3.ts(32,16): error TS2416: Property 'item' in type 'C1' is not assignable to the same property in base type 'string'.
|
||||
tests/cases/compiler/interfaceDeclaration3.ts(32,16): error TS2416: Property 'item' in type 'C1' is not assignable to the same property in base type 'I1'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/compiler/interfaceDeclaration3.ts(54,11): error TS2430: Interface 'I2' incorrectly extends interface 'I1'.
|
||||
Types of property 'item' are incompatible.
|
||||
@@ -16,7 +16,7 @@ tests/cases/compiler/interfaceDeclaration3.ts(54,11): error TS2430: Interface 'I
|
||||
class C1 implements I1 {
|
||||
public item:number;
|
||||
~~~~
|
||||
!!! error TS2416: Property 'item' in type 'C1' is not assignable to the same property in base type 'string'.
|
||||
!!! error TS2416: Property 'item' in type 'C1' is not assignable to the same property in base type 'I1'.
|
||||
!!! error TS2416: Type 'number' is not assignable to type 'string'.
|
||||
}
|
||||
class C2 implements I1 {
|
||||
@@ -44,7 +44,7 @@ tests/cases/compiler/interfaceDeclaration3.ts(54,11): error TS2430: Interface 'I
|
||||
class C1 implements I1 {
|
||||
public item:number;
|
||||
~~~~
|
||||
!!! error TS2416: Property 'item' in type 'C1' is not assignable to the same property in base type 'string'.
|
||||
!!! error TS2416: Property 'item' in type 'C1' is not assignable to the same property in base type 'I1'.
|
||||
!!! error TS2416: Type 'number' is not assignable to type 'string'.
|
||||
}
|
||||
class C2 implements I1 {
|
||||
|
||||
@@ -2,11 +2,13 @@ tests/cases/compiler/interfaceExtendsClassWithPrivate2.ts(10,7): error TS2415: C
|
||||
Types have separate declarations of a private property 'x'.
|
||||
tests/cases/compiler/interfaceExtendsClassWithPrivate2.ts(10,7): error TS2420: Class 'D' incorrectly implements interface 'I'.
|
||||
Types have separate declarations of a private property 'x'.
|
||||
tests/cases/compiler/interfaceExtendsClassWithPrivate2.ts(20,13): error TS2416: Property 'x' in type 'D2' is not assignable to the same property in base type 'number'.
|
||||
tests/cases/compiler/interfaceExtendsClassWithPrivate2.ts(20,13): error TS2416: Property 'x' in type 'D2' is not assignable to the same property in base type 'C'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/interfaceExtendsClassWithPrivate2.ts(20,13): error TS2416: Property 'x' in type 'D2' is not assignable to the same property in base type 'I'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/interfaceExtendsClassWithPrivate2.ts (3 errors) ====
|
||||
==== tests/cases/compiler/interfaceExtendsClassWithPrivate2.ts (4 errors) ====
|
||||
class C {
|
||||
public foo(x: any) { return x; }
|
||||
private x = 1;
|
||||
@@ -34,7 +36,10 @@ tests/cases/compiler/interfaceExtendsClassWithPrivate2.ts(20,13): error TS2416:
|
||||
public foo(x: any) { return x; }
|
||||
private x = "";
|
||||
~
|
||||
!!! error TS2416: Property 'x' in type 'D2' is not assignable to the same property in base type 'number'.
|
||||
!!! error TS2416: Property 'x' in type 'D2' is not assignable to the same property in base type 'C'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
~
|
||||
!!! error TS2416: Property 'x' in type 'D2' is not assignable to the same property in base type 'I'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
other(x: any) { return x; }
|
||||
bar() { }
|
||||
|
||||
@@ -14,15 +14,15 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(11,11): error TS2430: Interface 'I5' incorrectly extends interface 'T5'.
|
||||
Types of property 'c' are incompatible.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'number'.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(16,38): error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'number'.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(17,38): error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number'.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(18,38): error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type 'string'.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(19,38): error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'string'.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(20,38): error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'.
|
||||
Type 'number' is not assignable to type 'string'.
|
||||
tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(30,11): error TS2430: Interface 'I10' incorrectly extends interface 'typeof CX'.
|
||||
Types of property 'a' are incompatible.
|
||||
@@ -94,23 +94,23 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI
|
||||
|
||||
class C1 extends Constructor<T1>() { a: string }
|
||||
~
|
||||
!!! error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'number'.
|
||||
!!! error TS2416: Property 'a' in type 'C1' is not assignable to the same property in base type 'T1'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
class C2 extends Constructor<T2>() { b: string }
|
||||
~
|
||||
!!! error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'number'.
|
||||
!!! error TS2416: Property 'b' in type 'C2' is not assignable to the same property in base type 'T2'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
class C3 extends Constructor<T3>() { length: string }
|
||||
~~~~~~
|
||||
!!! error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number'.
|
||||
!!! error TS2416: Property 'length' in type 'C3' is not assignable to the same property in base type 'number[]'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
class C4 extends Constructor<T4>() { 0: number }
|
||||
~
|
||||
!!! error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type 'string'.
|
||||
!!! error TS2416: Property '0' in type 'C4' is not assignable to the same property in base type '[string, number]'.
|
||||
!!! error TS2416: Type 'number' is not assignable to type 'string'.
|
||||
class C5 extends Constructor<T5>() { c: number }
|
||||
~
|
||||
!!! error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'string'.
|
||||
!!! error TS2416: Property 'c' in type 'C5' is not assignable to the same property in base type 'T5'.
|
||||
!!! error TS2416: Type 'number' is not assignable to type 'string'.
|
||||
|
||||
declare class CX { static a: string }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
tests/cases/compiler/interfaceImplementation7.ts(4,11): error TS2320: Interface 'i3' cannot simultaneously extend types 'i1' and 'i2'.
|
||||
Named property 'name' of types 'i1' and 'i2' are not identical.
|
||||
tests/cases/compiler/interfaceImplementation7.ts(8,12): error TS2416: Property 'name' in type 'C1' is not assignable to the same property in base type '() => { s: string; n: number; }'.
|
||||
tests/cases/compiler/interfaceImplementation7.ts(8,12): error TS2416: Property 'name' in type 'C1' is not assignable to the same property in base type 'i4'.
|
||||
Type '() => string' is not assignable to type '() => { s: string; n: number; }'.
|
||||
Type 'string' is not assignable to type '{ s: string; n: number; }'.
|
||||
|
||||
@@ -18,7 +18,7 @@ tests/cases/compiler/interfaceImplementation7.ts(8,12): error TS2416: Property '
|
||||
class C1 implements i4 {
|
||||
public name(): string { return ""; }
|
||||
~~~~
|
||||
!!! error TS2416: Property 'name' in type 'C1' is not assignable to the same property in base type '() => { s: string; n: number; }'.
|
||||
!!! error TS2416: Property 'name' in type 'C1' is not assignable to the same property in base type 'i4'.
|
||||
!!! error TS2416: Type '() => string' is not assignable to type '() => { s: string; n: number; }'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type '{ s: string; n: number; }'.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//// [jsxHasLiteralType.tsx]
|
||||
import * as React from "react";
|
||||
|
||||
interface Props {
|
||||
x?: "a" | "b";
|
||||
}
|
||||
class MyComponent<P extends Props = Props> extends React.Component<P, {}> {}
|
||||
const m = <MyComponent x="a"/>
|
||||
|
||||
|
||||
//// [jsxHasLiteralType.js]
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
exports.__esModule = true;
|
||||
var React = require("react");
|
||||
var MyComponent = /** @class */ (function (_super) {
|
||||
__extends(MyComponent, _super);
|
||||
function MyComponent() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return MyComponent;
|
||||
}(React.Component));
|
||||
var m = React.createElement(MyComponent, { x: "a" });
|
||||
@@ -0,0 +1,25 @@
|
||||
=== tests/cases/compiler/jsxHasLiteralType.tsx ===
|
||||
import * as React from "react";
|
||||
>React : Symbol(React, Decl(jsxHasLiteralType.tsx, 0, 6))
|
||||
|
||||
interface Props {
|
||||
>Props : Symbol(Props, Decl(jsxHasLiteralType.tsx, 0, 31))
|
||||
|
||||
x?: "a" | "b";
|
||||
>x : Symbol(Props.x, Decl(jsxHasLiteralType.tsx, 2, 17))
|
||||
}
|
||||
class MyComponent<P extends Props = Props> extends React.Component<P, {}> {}
|
||||
>MyComponent : Symbol(MyComponent, Decl(jsxHasLiteralType.tsx, 4, 1))
|
||||
>P : Symbol(P, Decl(jsxHasLiteralType.tsx, 5, 18))
|
||||
>Props : Symbol(Props, Decl(jsxHasLiteralType.tsx, 0, 31))
|
||||
>Props : Symbol(Props, Decl(jsxHasLiteralType.tsx, 0, 31))
|
||||
>React.Component : Symbol(React.Component, Decl(react.d.ts, 158, 55), Decl(react.d.ts, 161, 66))
|
||||
>React : Symbol(React, Decl(jsxHasLiteralType.tsx, 0, 6))
|
||||
>Component : Symbol(React.Component, Decl(react.d.ts, 158, 55), Decl(react.d.ts, 161, 66))
|
||||
>P : Symbol(P, Decl(jsxHasLiteralType.tsx, 5, 18))
|
||||
|
||||
const m = <MyComponent x="a"/>
|
||||
>m : Symbol(m, Decl(jsxHasLiteralType.tsx, 6, 5))
|
||||
>MyComponent : Symbol(MyComponent, Decl(jsxHasLiteralType.tsx, 4, 1))
|
||||
>x : Symbol(x, Decl(jsxHasLiteralType.tsx, 6, 22))
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
=== tests/cases/compiler/jsxHasLiteralType.tsx ===
|
||||
import * as React from "react";
|
||||
>React : typeof React
|
||||
|
||||
interface Props {
|
||||
>Props : Props
|
||||
|
||||
x?: "a" | "b";
|
||||
>x : "a" | "b" | undefined
|
||||
}
|
||||
class MyComponent<P extends Props = Props> extends React.Component<P, {}> {}
|
||||
>MyComponent : MyComponent<P>
|
||||
>P : P
|
||||
>Props : Props
|
||||
>Props : Props
|
||||
>React.Component : React.Component<P, {}>
|
||||
>React : typeof React
|
||||
>Component : typeof React.Component
|
||||
>P : P
|
||||
|
||||
const m = <MyComponent x="a"/>
|
||||
>m : JSX.Element
|
||||
><MyComponent x="a"/> : JSX.Element
|
||||
>MyComponent : typeof MyComponent
|
||||
>x : "a"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
tests/cases/compiler/mismatchedGenericArguments1.ts(5,4): error TS2416: Property 'foo' in type 'C<T>' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
tests/cases/compiler/mismatchedGenericArguments1.ts(5,4): error TS2416: Property 'foo' in type 'C<T>' is not assignable to the same property in base type 'IFoo<T>'.
|
||||
Type '(x: string) => number' is not assignable to type '<T>(x: T) => T'.
|
||||
Types of parameters 'x' and 'x' are incompatible.
|
||||
Type 'T' is not assignable to type 'string'.
|
||||
tests/cases/compiler/mismatchedGenericArguments1.ts(11,4): error TS2416: Property 'foo' in type 'C2<T>' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
tests/cases/compiler/mismatchedGenericArguments1.ts(11,4): error TS2416: Property 'foo' in type 'C2<T>' is not assignable to the same property in base type 'IFoo<T>'.
|
||||
Type '<U>(x: string) => number' is not assignable to type '<T>(x: T) => T'.
|
||||
Types of parameters 'x' and 'x' are incompatible.
|
||||
Type 'T' is not assignable to type 'string'.
|
||||
@@ -15,7 +15,7 @@ tests/cases/compiler/mismatchedGenericArguments1.ts(11,4): error TS2416: Propert
|
||||
class C<T> implements IFoo<T> {
|
||||
foo(x: string): number {
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'C<T>' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Property 'foo' in type 'C<T>' is not assignable to the same property in base type 'IFoo<T>'.
|
||||
!!! error TS2416: Type '(x: string) => number' is not assignable to type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Types of parameters 'x' and 'x' are incompatible.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'string'.
|
||||
@@ -26,7 +26,7 @@ tests/cases/compiler/mismatchedGenericArguments1.ts(11,4): error TS2416: Propert
|
||||
class C2<T> implements IFoo<T> {
|
||||
foo<U>(x: string): number {
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'C2<T>' is not assignable to the same property in base type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Property 'foo' in type 'C2<T>' is not assignable to the same property in base type 'IFoo<T>'.
|
||||
!!! error TS2416: Type '<U>(x: string) => number' is not assignable to type '<T>(x: T) => T'.
|
||||
!!! error TS2416: Types of parameters 'x' and 'x' are incompatible.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'string'.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
tests/cases/compiler/multipleInheritance.ts(9,21): error TS1174: Classes can only extend a single class.
|
||||
tests/cases/compiler/multipleInheritance.ts(18,21): error TS1174: Classes can only extend a single class.
|
||||
tests/cases/compiler/multipleInheritance.ts(35,12): error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function.
|
||||
tests/cases/compiler/multipleInheritance.ts(36,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type '() => number'.
|
||||
tests/cases/compiler/multipleInheritance.ts(36,12): error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'.
|
||||
Type '(n: number) => number' is not assignable to type '() => number'.
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ tests/cases/compiler/multipleInheritance.ts(36,12): error TS2416: Property 'g' i
|
||||
!!! error TS2425: Class 'Good' defines instance member property 'f', but extended class 'Baad' defines it as instance member function.
|
||||
public g(n:number) { return 0; }
|
||||
~
|
||||
!!! error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type '() => number'.
|
||||
!!! error TS2416: Property 'g' in type 'Baad' is not assignable to the same property in base type 'Good'.
|
||||
!!! error TS2416: Type '(n: number) => number' is not assignable to type '() => number'.
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/compiler/requiredInitializedParameter2.ts(6,5): error TS2416: Property 'method' in type 'C1' is not assignable to the same property in base type '() => any'.
|
||||
tests/cases/compiler/requiredInitializedParameter2.ts(6,5): error TS2416: Property 'method' in type 'C1' is not assignable to the same property in base type 'I1'.
|
||||
Type '(a: number, b: any) => void' is not assignable to type '() => any'.
|
||||
|
||||
|
||||
@@ -10,6 +10,6 @@ tests/cases/compiler/requiredInitializedParameter2.ts(6,5): error TS2416: Proper
|
||||
class C1 implements I1 {
|
||||
method(a = 0, b) { }
|
||||
~~~~~~
|
||||
!!! error TS2416: Property 'method' in type 'C1' is not assignable to the same property in base type '() => any'.
|
||||
!!! error TS2416: Property 'method' in type 'C1' is not assignable to the same property in base type 'I1'.
|
||||
!!! error TS2416: Type '(a: number, b: any) => void' is not assignable to type '() => any'.
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2416: Property 'foo' in type 'D1<T, U>' is not assignable to the same property in base type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameter.ts(8,5): error TS2416: Property 'foo' in type 'D1<T, U>' is not assignable to the same property in base type 'C3<T>'.
|
||||
Type 'U' is not assignable to type 'T'.
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
class D1<T, U> extends C3<T> {
|
||||
foo: U; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D1<T, U>' is not assignable to the same property in base type 'T'.
|
||||
!!! error TS2416: Property 'foo' in type 'D1<T, U>' is not assignable to the same property in base type 'C3<T>'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'T'.
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2416: Property 'foo' in type 'D3<T, U>' is not assignable to the same property in base type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2416: Property 'foo' in type 'D3<T, U>' is not assignable to the same property in base type 'C3<T>'.
|
||||
Type 'U' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'C3<T>'.
|
||||
Type 'U' is not assignable to type 'T'.
|
||||
Type 'V' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2416: Property 'foo' in type 'D11<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2416: Property 'foo' in type 'D11<T, U, V>' is not assignable to the same property in base type 'C3<T>'.
|
||||
Type 'V' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2416: Property 'foo' in type 'D12<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2416: Property 'foo' in type 'D12<T, U, V>' is not assignable to the same property in base type 'C3<U>'.
|
||||
Type 'V' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2416: Property 'foo' in type 'D19<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2416: Property 'foo' in type 'D19<T, U, V>' is not assignable to the same property in base type 'C3<T>'.
|
||||
Type 'U' is not assignable to type 'T'.
|
||||
Type 'V' is not assignable to type 'T'.
|
||||
Type 'Date' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2416: Property 'foo' in type 'D23<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2416: Property 'foo' in type 'D23<T, U, V>' is not assignable to the same property in base type 'C3<T>'.
|
||||
Type 'V' is not assignable to type 'T'.
|
||||
Type 'Date' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2416: Property 'foo' in type 'D24<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2416: Property 'foo' in type 'D24<T, U, V>' is not assignable to the same property in base type 'C3<U>'.
|
||||
Type 'V' is not assignable to type 'U'.
|
||||
Type 'Date' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2416: Property 'foo' in type 'D27<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2416: Property 'foo' in type 'D27<T, U, V>' is not assignable to the same property in base type 'C3<T>'.
|
||||
Type 'Date' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2416: Property 'foo' in type 'D28<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2416: Property 'foo' in type 'D28<T, U, V>' is not assignable to the same property in base type 'C3<U>'.
|
||||
Type 'Date' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2416: Property 'foo' in type 'D29<T, U, V>' is not assignable to the same property in base type 'V'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2416: Property 'foo' in type 'D29<T, U, V>' is not assignable to the same property in base type 'C3<V>'.
|
||||
Type 'Date' is not assignable to type 'V'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'V'.
|
||||
|
||||
@@ -56,7 +56,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: U; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D3<T, U>' is not assignable to the same property in base type 'T'.
|
||||
!!! error TS2416: Property 'foo' in type 'D3<T, U>' is not assignable to the same property in base type 'C3<T>'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'T'.
|
||||
~~~~~~~
|
||||
!!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'.
|
||||
@@ -92,7 +92,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: U; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
!!! error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'C3<T>'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'T'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'T'.
|
||||
~~~~~~~
|
||||
@@ -115,7 +115,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: V; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D11<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
!!! error TS2416: Property 'foo' in type 'D11<T, U, V>' is not assignable to the same property in base type 'C3<T>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'T'.
|
||||
~~~~~~~
|
||||
!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'.
|
||||
@@ -125,7 +125,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: U;
|
||||
foo: V; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D12<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
!!! error TS2416: Property 'foo' in type 'D12<T, U, V>' is not assignable to the same property in base type 'C3<U>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'U'.
|
||||
~~~~~~~
|
||||
!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'.
|
||||
@@ -170,7 +170,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: U; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D19<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
!!! error TS2416: Property 'foo' in type 'D19<T, U, V>' is not assignable to the same property in base type 'C3<T>'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'T'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'T'.
|
||||
!!! error TS2416: Type 'Date' is not assignable to type 'T'.
|
||||
@@ -199,7 +199,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: V; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D23<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
!!! error TS2416: Property 'foo' in type 'D23<T, U, V>' is not assignable to the same property in base type 'C3<T>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'T'.
|
||||
!!! error TS2416: Type 'Date' is not assignable to type 'T'.
|
||||
~~~~~~~
|
||||
@@ -210,7 +210,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: U;
|
||||
foo: V; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D24<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
!!! error TS2416: Property 'foo' in type 'D24<T, U, V>' is not assignable to the same property in base type 'C3<U>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'U'.
|
||||
!!! error TS2416: Type 'Date' is not assignable to type 'U'.
|
||||
~~~~~~~
|
||||
@@ -233,7 +233,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: Date; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D27<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
!!! error TS2416: Property 'foo' in type 'D27<T, U, V>' is not assignable to the same property in base type 'C3<T>'.
|
||||
!!! error TS2416: Type 'Date' is not assignable to type 'T'.
|
||||
~~~~~~~~~~
|
||||
!!! error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'T'.
|
||||
@@ -243,7 +243,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: U;
|
||||
foo: Date; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D28<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
!!! error TS2416: Property 'foo' in type 'D28<T, U, V>' is not assignable to the same property in base type 'C3<U>'.
|
||||
!!! error TS2416: Type 'Date' is not assignable to type 'U'.
|
||||
~~~~~~~~~~
|
||||
!!! error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'U'.
|
||||
@@ -253,7 +253,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: V;
|
||||
foo: Date; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D29<T, U, V>' is not assignable to the same property in base type 'V'.
|
||||
!!! error TS2416: Property 'foo' in type 'D29<T, U, V>' is not assignable to the same property in base type 'C3<V>'.
|
||||
!!! error TS2416: Type 'Date' is not assignable to type 'V'.
|
||||
~~~~~~~~~~
|
||||
!!! error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'V'.
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'Foo'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'B1<Foo>'.
|
||||
Type 'V' is not assignable to type 'Foo'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'Foo'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2416: Property 'foo' in type 'D5<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2416: Property 'foo' in type 'D5<T, U, V>' is not assignable to the same property in base type 'B1<T>'.
|
||||
Type 'U' is not assignable to type 'T'.
|
||||
Type 'Foo' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'B1<T>'.
|
||||
Type 'V' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'B1<U>'.
|
||||
Type 'T' is not assignable to type 'U'.
|
||||
Type 'Foo' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2416: Property 'foo' in type 'D9<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2416: Property 'foo' in type 'D9<T, U, V>' is not assignable to the same property in base type 'B1<U>'.
|
||||
Type 'V' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'.
|
||||
|
||||
@@ -66,7 +66,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: Foo;
|
||||
foo: V; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'Foo'.
|
||||
!!! error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'B1<Foo>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'Foo'.
|
||||
~~~~~~~
|
||||
!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'Foo'.
|
||||
@@ -81,7 +81,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: U; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D5<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
!!! error TS2416: Property 'foo' in type 'D5<T, U, V>' is not assignable to the same property in base type 'B1<T>'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'T'.
|
||||
!!! error TS2416: Type 'Foo' is not assignable to type 'T'.
|
||||
~~~~~~~
|
||||
@@ -92,7 +92,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: V; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
!!! error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'B1<T>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'T'.
|
||||
~~~~~~~
|
||||
!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'.
|
||||
@@ -102,7 +102,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: U;
|
||||
foo: T; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
!!! error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'B1<U>'.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'U'.
|
||||
!!! error TS2416: Type 'Foo' is not assignable to type 'U'.
|
||||
~~~~~~~
|
||||
@@ -118,7 +118,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: U;
|
||||
foo: V; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D9<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
!!! error TS2416: Property 'foo' in type 'D9<T, U, V>' is not assignable to the same property in base type 'B1<U>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'U'.
|
||||
~~~~~~~
|
||||
!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'.
|
||||
|
||||
+24
-24
@@ -1,58 +1,58 @@
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2416: Property 'foo' in type 'D2<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2416: Property 'foo' in type 'D2<T, U, V>' is not assignable to the same property in base type 'Base<T>'.
|
||||
Type 'U' is not assignable to type 'T'.
|
||||
Type 'Foo<T>' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'Base<T>'.
|
||||
Type 'V' is not assignable to type 'T'.
|
||||
Type 'Foo<V>' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2416: Property 'foo' in type 'D4<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2416: Property 'foo' in type 'D4<T, U, V>' is not assignable to the same property in base type 'Base<U>'.
|
||||
Type 'T' is not assignable to type 'U'.
|
||||
Type 'Foo<U>' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'Base<U>'.
|
||||
Type 'V' is not assignable to type 'U'.
|
||||
Type 'Foo<V>' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'V'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'Base<V>'.
|
||||
Type 'T' is not assignable to type 'V'.
|
||||
Type 'Foo<U>' is not assignable to type 'V'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'V'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'Base<V>'.
|
||||
Type 'U' is not assignable to type 'V'.
|
||||
Type 'Foo<T>' is not assignable to type 'V'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2416: Property 'foo' in type 'D1<T, U, V>' is not assignable to the same property in base type 'Foo<T>'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(115,9): error TS2416: Property 'foo' in type 'D1<T, U, V>' is not assignable to the same property in base type 'Base2<T>'.
|
||||
Type 'T' is not assignable to type 'Foo<T>'.
|
||||
Type 'Foo<U>' is not assignable to type 'Foo<T>'.
|
||||
Type 'U' is not assignable to type 'T'.
|
||||
Type 'Foo<T>' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'Foo<T>'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'Base2<T>'.
|
||||
Type 'V' is not assignable to type 'Foo<T>'.
|
||||
Type 'Foo<V>' is not assignable to type 'Foo<T>'.
|
||||
Type 'V' is not assignable to type 'T'.
|
||||
Type 'Foo<V>' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2416: Property 'foo' in type 'D5<T, U, V>' is not assignable to the same property in base type 'Foo<U>'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2416: Property 'foo' in type 'D5<T, U, V>' is not assignable to the same property in base type 'Base2<U>'.
|
||||
Type 'U' is not assignable to type 'Foo<U>'.
|
||||
Type 'Foo<T>' is not assignable to type 'Foo<U>'.
|
||||
Type 'T' is not assignable to type 'U'.
|
||||
Type 'Foo<U>' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'Foo<U>'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'Base2<U>'.
|
||||
Type 'V' is not assignable to type 'Foo<U>'.
|
||||
Type 'Foo<V>' is not assignable to type 'Foo<U>'.
|
||||
Type 'V' is not assignable to type 'U'.
|
||||
Type 'Foo<V>' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'Foo<V>'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'Base2<V>'.
|
||||
Type 'T' is not assignable to type 'Foo<V>'.
|
||||
Type 'Foo<U>' is not assignable to type 'Foo<V>'.
|
||||
Type 'U' is not assignable to type 'V'.
|
||||
Type 'Foo<T>' is not assignable to type 'V'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'Foo<V>'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'Base2<V>'.
|
||||
Type 'U' is not assignable to type 'Foo<V>'.
|
||||
Type 'Foo<T>' is not assignable to type 'Foo<V>'.
|
||||
Type 'T' is not assignable to type 'V'.
|
||||
@@ -130,7 +130,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: U
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D2<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
!!! error TS2416: Property 'foo' in type 'D2<T, U, V>' is not assignable to the same property in base type 'Base<T>'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'T'.
|
||||
!!! error TS2416: Type 'Foo<T>' is not assignable to type 'T'.
|
||||
~~~~~~
|
||||
@@ -141,7 +141,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: V
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'T'.
|
||||
!!! error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'Base<T>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'T'.
|
||||
!!! error TS2416: Type 'Foo<V>' is not assignable to type 'T'.
|
||||
~~~~~~
|
||||
@@ -152,7 +152,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: U;
|
||||
foo: T
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D4<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
!!! error TS2416: Property 'foo' in type 'D4<T, U, V>' is not assignable to the same property in base type 'Base<U>'.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'U'.
|
||||
!!! error TS2416: Type 'Foo<U>' is not assignable to type 'U'.
|
||||
~~~~~~
|
||||
@@ -168,7 +168,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: U;
|
||||
foo: V
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'U'.
|
||||
!!! error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'Base<U>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'U'.
|
||||
!!! error TS2416: Type 'Foo<V>' is not assignable to type 'U'.
|
||||
~~~~~~
|
||||
@@ -179,7 +179,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: V;
|
||||
foo: T
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'V'.
|
||||
!!! error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'Base<V>'.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'V'.
|
||||
!!! error TS2416: Type 'Foo<U>' is not assignable to type 'V'.
|
||||
~~~~~~
|
||||
@@ -190,7 +190,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: V;
|
||||
foo: U
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'V'.
|
||||
!!! error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'Base<V>'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'V'.
|
||||
!!! error TS2416: Type 'Foo<T>' is not assignable to type 'V'.
|
||||
~~~~~~
|
||||
@@ -213,7 +213,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: T
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D1<T, U, V>' is not assignable to the same property in base type 'Foo<T>'.
|
||||
!!! error TS2416: Property 'foo' in type 'D1<T, U, V>' is not assignable to the same property in base type 'Base2<T>'.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'Foo<T>'.
|
||||
!!! error TS2416: Type 'Foo<U>' is not assignable to type 'Foo<T>'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'T'.
|
||||
@@ -231,7 +231,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: T;
|
||||
foo: V
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'Foo<T>'.
|
||||
!!! error TS2416: Property 'foo' in type 'D3<T, U, V>' is not assignable to the same property in base type 'Base2<T>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'Foo<T>'.
|
||||
!!! error TS2416: Type 'Foo<V>' is not assignable to type 'Foo<T>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'T'.
|
||||
@@ -251,7 +251,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: U;
|
||||
foo: U
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D5<T, U, V>' is not assignable to the same property in base type 'Foo<U>'.
|
||||
!!! error TS2416: Property 'foo' in type 'D5<T, U, V>' is not assignable to the same property in base type 'Base2<U>'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'Foo<U>'.
|
||||
!!! error TS2416: Type 'Foo<T>' is not assignable to type 'Foo<U>'.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'U'.
|
||||
@@ -262,7 +262,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: U;
|
||||
foo: V
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'Foo<U>'.
|
||||
!!! error TS2416: Property 'foo' in type 'D6<T, U, V>' is not assignable to the same property in base type 'Base2<U>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'Foo<U>'.
|
||||
!!! error TS2416: Type 'Foo<V>' is not assignable to type 'Foo<U>'.
|
||||
!!! error TS2416: Type 'V' is not assignable to type 'U'.
|
||||
@@ -275,7 +275,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: V;
|
||||
foo: T
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'Foo<V>'.
|
||||
!!! error TS2416: Property 'foo' in type 'D7<T, U, V>' is not assignable to the same property in base type 'Base2<V>'.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'Foo<V>'.
|
||||
!!! error TS2416: Type 'Foo<U>' is not assignable to type 'Foo<V>'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'V'.
|
||||
@@ -288,7 +288,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf
|
||||
[x: string]: V;
|
||||
foo: U
|
||||
~~~
|
||||
!!! error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'Foo<V>'.
|
||||
!!! error TS2416: Property 'foo' in type 'D8<T, U, V>' is not assignable to the same property in base type 'Base2<V>'.
|
||||
!!! error TS2416: Type 'U' is not assignable to type 'Foo<V>'.
|
||||
!!! error TS2416: Type 'Foo<T>' is not assignable to type 'Foo<V>'.
|
||||
!!! error TS2416: Type 'T' is not assignable to type 'V'.
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'Base'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(14,5): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'.
|
||||
Type 'string' is not assignable to type 'Base'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'Base'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(24,5): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'.
|
||||
Type 'string' is not assignable to type 'Base'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2416: Property '2.0' in type 'B3' is not assignable to the same property in base type 'Base'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(34,5): error TS2416: Property '2.0' in type 'B3' is not assignable to the same property in base type 'A3'.
|
||||
Type 'string' is not assignable to type 'Base'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'Base'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(45,9): error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'.
|
||||
Type 'string' is not assignable to type 'Base'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'Base'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(55,9): error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'.
|
||||
Type 'string' is not assignable to type 'Base'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2416: Property '2.0' in type 'B3' is not assignable to the same property in base type 'Base'.
|
||||
tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers.ts(65,9): error TS2416: Property '2.0' in type 'B3' is not assignable to the same property in base type 'A3'.
|
||||
Type 'string' is not assignable to type 'Base'.
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
|
||||
foo: Derived; // ok
|
||||
bar: string; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'Base'.
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
|
||||
1: Derived; // ok
|
||||
2: string; // error
|
||||
~
|
||||
!!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'Base'.
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
|
||||
'1': Derived; // ok
|
||||
'2.0': string; // error
|
||||
~~~~~
|
||||
!!! error TS2416: Property '2.0' in type 'B3' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Property '2.0' in type 'B3' is not assignable to the same property in base type 'A3'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'Base'.
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
|
||||
foo: Derived2; // ok
|
||||
bar: string; // error
|
||||
~~~
|
||||
!!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Property 'bar' in type 'B' is not assignable to the same property in base type 'A'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'Base'.
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
|
||||
1: Derived2; // ok
|
||||
2: string; // error
|
||||
~
|
||||
!!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Property '2' in type 'B2' is not assignable to the same property in base type 'A2'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'Base'.
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW
|
||||
'1': Derived2; // ok
|
||||
'2.0': string; // error
|
||||
~~~~~
|
||||
!!! error TS2416: Property '2.0' in type 'B3' is not assignable to the same property in base type 'Base'.
|
||||
!!! error TS2416: Property '2.0' in type 'B3' is not assignable to the same property in base type 'A3'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'Base'.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// @noImplicitAny: true
|
||||
|
||||
type Foo = {[P in "bar"]};
|
||||
@@ -0,0 +1,11 @@
|
||||
// @strictNullChecks: true
|
||||
// @jsx: react
|
||||
// @skipLibCheck: true
|
||||
// @libFiles: lib.d.ts,react.d.ts
|
||||
import * as React from "react";
|
||||
|
||||
interface Props {
|
||||
x?: "a" | "b";
|
||||
}
|
||||
class MyComponent<P extends Props = Props> extends React.Component<P, {}> {}
|
||||
const m = <MyComponent x="a"/>
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////function f() {
|
||||
//// await Promise.resolve();
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`async function f() {
|
||||
await Promise.resolve();
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const f: () => number | string = () => {
|
||||
//// await Promise.resolve('foo');
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`const f: () => Promise<number | string> = async () => {
|
||||
await Promise.resolve('foo');
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const f: string = () => {
|
||||
//// await Promise.resolve('foo');
|
||||
////}
|
||||
|
||||
// should not change type if it's incorrectly set
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`const f: string = async () => {
|
||||
await Promise.resolve('foo');
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const f: () => Array<number | string> = function() {
|
||||
//// await Promise.resolve([]);
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`const f: () => Promise<Array<number | string>> = async function() {
|
||||
await Promise.resolve([]);
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const f: () => Promise<number | string> = () => {
|
||||
//// await Promise.resolve('foo');
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`const f: () => Promise<number | string> = async () => {
|
||||
await Promise.resolve('foo');
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const f = function(): number {
|
||||
//// await Promise.resolve(1);
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`const f = async function(): Promise<number> {
|
||||
await Promise.resolve(1);
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const f = (): number[] => {
|
||||
//// await Promise.resolve([1]);
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`const f = async (): Promise<number[]> => {
|
||||
await Promise.resolve([1]);
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const f = function() {
|
||||
//// await Promise.resolve();
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`const f = async function() {
|
||||
await Promise.resolve();
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const f = {
|
||||
//// get a() {
|
||||
//// return await Promise.resolve();
|
||||
//// },
|
||||
//// get a() {
|
||||
//// await Promise.resolve();
|
||||
//// },
|
||||
////}
|
||||
|
||||
verify.not.codeFixAvailable();
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////class Foo {
|
||||
//// constructor {
|
||||
//// await Promise.resolve();
|
||||
//// }
|
||||
////}
|
||||
|
||||
verify.not.codeFixAvailable();
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////class Foo {
|
||||
//// bar() {
|
||||
//// await Promise.resolve();
|
||||
//// }
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`class Foo {
|
||||
async bar() {
|
||||
await Promise.resolve();
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const f = promise => {
|
||||
//// await promise;
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`const f = async promise => {
|
||||
await promise;
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const f = (promise) => {
|
||||
//// await promise;
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`const f = async (promise) => {
|
||||
await promise;
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////function f() {
|
||||
//// for await (const x of g()) {
|
||||
//// console.log(x);
|
||||
//// }
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`async function f() {
|
||||
for await (const x of g()) {
|
||||
console.log(x);
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////function f(): number | string {
|
||||
//// await Promise.resolve(8);
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`async function f(): Promise<number | string> {
|
||||
await Promise.resolve(8);
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////class Foo {
|
||||
//// bar(): string {
|
||||
//// await Promise.resolve('baz');
|
||||
//// }
|
||||
////}
|
||||
|
||||
verify.codeFix({
|
||||
description: "Add async modifier to containing function",
|
||||
newFileContent:
|
||||
`class Foo {
|
||||
async bar(): Promise<string> {
|
||||
await Promise.resolve('baz');
|
||||
}
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////function f() {
|
||||
//// await Promise.resolve();
|
||||
////}
|
||||
////
|
||||
////const g = () => {
|
||||
//// await f();
|
||||
////}
|
||||
|
||||
verify.codeFixAll({
|
||||
fixId: "fixAwaitInSyncFunction",
|
||||
newFileContent:
|
||||
`async function f() {
|
||||
await Promise.resolve();
|
||||
}
|
||||
|
||||
const g = async () => {
|
||||
await f();
|
||||
}`,
|
||||
});
|
||||
@@ -3,6 +3,9 @@
|
||||
// @Filename: /src/b.ts
|
||||
////export const x = 0;
|
||||
|
||||
// @Filename: /src/dir/x.ts
|
||||
/////export const x = 0;
|
||||
|
||||
// @Filename: /src/a.ts
|
||||
////import {} from "foo/[|/**/|]";
|
||||
|
||||
@@ -17,4 +20,8 @@
|
||||
////}
|
||||
|
||||
const [replacementSpan] = test.ranges();
|
||||
verify.completionsAt("", [{ name: "a", replacementSpan }, { name: "b", replacementSpan }]);
|
||||
verify.completionsAt("", [
|
||||
{ name: "a", replacementSpan },
|
||||
{ name: "b", replacementSpan },
|
||||
{ name: "dir", replacementSpan },
|
||||
]);
|
||||
|
||||
@@ -135,6 +135,7 @@ declare namespace FourSlashInterface {
|
||||
file(index: number, content?: string, scriptKindName?: string): any;
|
||||
file(name: string, content?: string, scriptKindName?: string): any;
|
||||
select(startMarker: string, endMarker: string): void;
|
||||
selectRange(range: Range): void;
|
||||
}
|
||||
class verifyNegatable {
|
||||
private negative;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
////const exportsAlias = exports;
|
||||
////exportsAlias.f = function() {};
|
||||
/////*a*/module/*b*/.exports = exportsAlias;
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert to ES6 module",
|
||||
actionName: "Convert to ES6 module",
|
||||
actionDescription: "Convert to ES6 module",
|
||||
newContent: `
|
||||
export function f() { }
|
||||
`,
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// Test that we leave it alone if the name is a keyword.
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
/////*a*/exports/*b*/.default = 0;
|
||||
////exports.default;
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert to ES6 module",
|
||||
actionName: "Convert to ES6 module",
|
||||
actionDescription: "Convert to ES6 module",
|
||||
newContent: `const _default = 0;
|
||||
export { _default as default };
|
||||
_default;`,
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// Test that we leave it alone if the name is a keyword.
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
/////*a*/exports/*b*/.class = 0;
|
||||
////exports.async = 1;
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert to ES6 module",
|
||||
actionName: "Convert to ES6 module",
|
||||
actionDescription: "Convert to ES6 module",
|
||||
newContent: `const _class = 0;
|
||||
export { _class as class };
|
||||
export const async = 1;`,
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
/////*a*/module/*b*/.exports = function() {}
|
||||
////module.exports = function f() {}
|
||||
////module.exports = class {}
|
||||
////module.exports = class C {}
|
||||
////module.exports = 0;
|
||||
|
||||
// See also `refactorConvertToEs6Module_export_moduleDotExportsEqualsRequire.ts`
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert to ES6 module",
|
||||
actionName: "Convert to ES6 module",
|
||||
actionDescription: "Convert to ES6 module",
|
||||
newContent: `export default function() { }
|
||||
export default function f() { }
|
||||
export default class {
|
||||
}
|
||||
export default class C {
|
||||
}
|
||||
export default 0;`
|
||||
});
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.d.ts
|
||||
////export const x: number;
|
||||
|
||||
// @Filename: /b.d.ts
|
||||
////export default function f() {}
|
||||
|
||||
// @Filename: /c.d.ts
|
||||
////export default function f(): void;
|
||||
////export function g(): void;
|
||||
|
||||
// @Filename: /d.ts
|
||||
////declare const x: number;
|
||||
////export = x;
|
||||
|
||||
// @Filename: /z.js
|
||||
// Normally -- just `export *`
|
||||
/////*a*/module/*b*/.exports = require("./a");
|
||||
// If just a default is exported, just `export { default }`
|
||||
////module.exports = require("./b");
|
||||
// May need both
|
||||
////module.exports = require("./c");
|
||||
// For `export =` re-export the "default" since that's what it will be converted to.
|
||||
////module.exports = require("./d");
|
||||
// In untyped case just go with `export *`
|
||||
////module.exports = require("./unknown");
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert to ES6 module",
|
||||
actionName: "Convert to ES6 module",
|
||||
actionDescription: "Convert to ES6 module",
|
||||
newContent:
|
||||
`export * from "./a";
|
||||
export { default } from "./b";
|
||||
export * from "./c";
|
||||
export { default } from "./c";
|
||||
export { default } from "./d";
|
||||
export * from "./unknown";`,
|
||||
});
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
/////*a*/module/*b*/.exports = 0;
|
||||
|
||||
// @Filename: /b.ts
|
||||
////import a = require("./a");
|
||||
|
||||
// @Filename: /c.js
|
||||
////const a = require("./a");
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert to ES6 module",
|
||||
actionName: "Convert to ES6 module",
|
||||
actionDescription: "Convert to ES6 module",
|
||||
newContent: `export default 0;`,
|
||||
});
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.currentFileContentIs('import a from "./a";');
|
||||
|
||||
goTo.file("/c.js");
|
||||
verify.currentFileContentIs('const a = require("./a").default;');
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
/////*a*/exports/*b*/.f = function() {}
|
||||
////exports.C = class {}
|
||||
////exports.x = 0;
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert to ES6 module",
|
||||
actionName: "Convert to ES6 module",
|
||||
actionDescription: "Convert to ES6 module",
|
||||
newContent: `export function f() { }
|
||||
export class C {
|
||||
}
|
||||
export const x = 0;`,
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
/////*a*/module/*b*/.exports = {
|
||||
//// x: 0,
|
||||
//// f: function() {},
|
||||
//// g: () => {},
|
||||
//// h() {},
|
||||
//// C: class {},
|
||||
////};
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert to ES6 module",
|
||||
actionName: "Convert to ES6 module",
|
||||
actionDescription: "Convert to ES6 module",
|
||||
newContent: `export const x = 0;
|
||||
export function f() { }
|
||||
export function g() { }
|
||||
export function h() { }
|
||||
export class C {
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// TODO: Maybe we could transform this to `export function f() {}`.
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
////function f() {}
|
||||
/////*a*/module/*b*/.exports = { f };
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert to ES6 module",
|
||||
actionName: "Convert to ES6 module",
|
||||
actionDescription: "Convert to ES6 module",
|
||||
newContent: `function f() {}
|
||||
export default { f };`,
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
////exports.x = 0;
|
||||
////exports.x;
|
||||
////
|
||||
////const y = 1;
|
||||
/////*a*/exports/*b*/.y = y;
|
||||
////exports.y;
|
||||
////
|
||||
////exports.z = 2;
|
||||
////function f(z) {
|
||||
//// exports.z;
|
||||
////}
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert to ES6 module",
|
||||
actionName: "Convert to ES6 module",
|
||||
actionDescription: "Convert to ES6 module",
|
||||
newContent: `export const x = 0;
|
||||
x;
|
||||
|
||||
const y = 1;
|
||||
const _y = y;
|
||||
export { _y as y };
|
||||
_y;
|
||||
|
||||
const _z = 2;
|
||||
export { _z as z };
|
||||
function f(z) {
|
||||
_z;
|
||||
}`,
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @allowJs: true
|
||||
|
||||
// @Filename: /a.js
|
||||
/////*a*/exports/*b*/.f = async function* f(p) {}
|
||||
////exports.C = class C extends D { m() {} }
|
||||
|
||||
goTo.select("a", "b");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Convert to ES6 module",
|
||||
actionName: "Convert to ES6 module",
|
||||
actionDescription: "Convert to ES6 module",
|
||||
newContent: `export async function* f(p) { }
|
||||
export class C extends D {
|
||||
m() { }
|
||||
}`,
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user