Merge pull request #7950 from Microsoft/sourceMapUpdatesForClasses

Source map updates for classes
This commit is contained in:
Ron Buckton
2016-04-18 12:43:13 -07:00
16 changed files with 215 additions and 98 deletions
+1 -1
View File
@@ -5678,7 +5678,7 @@ namespace ts {
}
}
if (target.flags & TypeFlags.Union) {
if (result = typeRelatedToSomeType(source, <UnionType>target, reportErrors)) {
if (result = typeRelatedToSomeType(source, <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive))) {
return result;
}
}
+27 -5
View File
@@ -13,7 +13,10 @@ namespace ts {
getTrailingCommentsOfPosition(pos: number): CommentRange[];
emitLeadingComments(range: TextRange, comments: CommentRange[]): void;
emitTrailingComments(range: TextRange, comments: CommentRange[]): void;
emitDetachedComments(range: TextRange): void;
emitLeadingDetachedComments(range: TextRange): void;
emitLeadingDetachedComments(range: TextRange, contextNode: Node, shouldSkipCommentsForNodeCallback: (node: Node) => boolean): void;
emitTrailingDetachedComments(range: TextRange): void;
emitTrailingDetachedComments(range: TextRange, contextNode: Node, shouldSkipCommentsForNodeCallback: (node: Node) => boolean): void;
}
export function createCommentWriter(host: EmitHost, writer: EmitTextWriter, sourceMap: SourceMapWriter): CommentWriter {
@@ -46,10 +49,15 @@ namespace ts {
getTrailingCommentsOfPosition(pos: number): CommentRange[] { return undefined; },
emitLeadingComments(range: TextRange, comments: CommentRange[]): void { },
emitTrailingComments(range: TextRange, comments: CommentRange[]): void { },
emitDetachedComments,
emitLeadingDetachedComments,
emitTrailingDetachedComments(node: TextRange, contextNode?: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean): void {}
};
function emitDetachedComments(node: TextRange): void {
function emitLeadingDetachedComments(node: TextRange, contextNode?: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean): void {
if (shouldSkipCommentsForNodeCallback && shouldSkipCommentsForNodeCallback(contextNode)) {
return;
}
emitDetachedCommentsAndUpdateCommentsInfo(node, /*removeComments*/ true);
}
}
@@ -65,7 +73,8 @@ namespace ts {
getTrailingCommentsOfPosition,
emitLeadingComments,
emitTrailingComments,
emitDetachedComments,
emitLeadingDetachedComments,
emitTrailingDetachedComments
};
function getLeadingComments(range: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean): CommentRange[];
@@ -154,10 +163,23 @@ namespace ts {
emitComments(currentText, currentLineMap, writer, comments, /*leadingSeparator*/ true, /*trailingSeparator*/ false, newLine, writeComment);
}
function emitDetachedComments(range: TextRange) {
function emitLeadingDetachedComments(range: TextRange, contextNode?: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean): void {
if (shouldSkipCommentsForNodeCallback && shouldSkipCommentsForNodeCallback(contextNode)) {
return;
}
emitDetachedCommentsAndUpdateCommentsInfo(range, /*removeComments*/ false);
}
function emitTrailingDetachedComments(range: TextRange, contextNode?: Node, shouldSkipCommentsForNodeCallback?: (node: Node) => boolean): void {
if (shouldSkipCommentsForNodeCallback && shouldSkipCommentsForNodeCallback(contextNode)) {
return;
}
range = collapseRangeToEnd(range);
emitLeadingComments(range, getLeadingComments(range));
}
function hasConsumedCommentRange(comment: CommentRange) {
return comment.end === consumedCommentRanges[comment.pos];
}
+5 -4
View File
@@ -651,13 +651,14 @@ namespace ts {
/**
* Creates a synthetic expression to act as a placeholder for a not-emitted expression in
* order to preserve comments.
* order to preserve comments or sourcemap positions.
*
* @param expression The inner expression to emit.
* @param original The original outer expression.
* @param location The location for the expression. Defaults to the positions from "original" if provided.
*/
export function createPartiallyEmittedExpression(expression: Expression, original: Node) {
const node = <PartiallyEmittedExpression>createNode(SyntaxKind.PartiallyEmittedExpression, /*location*/ original);
export function createPartiallyEmittedExpression(expression: Expression, original?: Node, location?: TextRange) {
const node = <PartiallyEmittedExpression>createNode(SyntaxKind.PartiallyEmittedExpression, /*location*/ location || original);
node.expression = expression;
node.original = original;
return node;
@@ -1257,7 +1258,7 @@ namespace ts {
* The function needs to be called during each transformation step.
* This function needs to be called whenever we transform the statement
* list of a source file, namespace, or function-like body.
*
*
* @param target: result statements array
* @param source: origin statements array
* @param ensureUseStrict: boolean determining whether the function need to add prologue-directives
+47 -30
View File
@@ -140,7 +140,8 @@ const _super = (function (geti, seti) {
getTrailingCommentsOfPosition,
emitLeadingComments,
emitTrailingComments,
emitDetachedComments
emitLeadingDetachedComments,
emitTrailingDetachedComments
} = comments;
let context: TransformationContext;
@@ -298,24 +299,45 @@ const _super = (function (geti, seti) {
const leadingComments = getLeadingComments(node, shouldSkipCommentsForNode);
const trailingComments = getTrailingComments(node, shouldSkipCommentsForNode);
emitLeadingComments(node, leadingComments);
emitStart(node, shouldIgnoreSourceMapForNode, shouldIgnoreSourceMapForChildren);
emitStart(node, shouldSkipSourceMapForNode, shouldSkipSourceMapForChildren);
emitWorker(node);
emitEnd(node, shouldIgnoreSourceMapForNode, shouldIgnoreSourceMapForChildren);
emitEnd(node, shouldSkipSourceMapForNode, shouldSkipSourceMapForChildren);
emitTrailingComments(node, trailingComments);
}
}
/**
* Determines whether to skip comment emit for a node.
*
* We do not emit comments for NotEmittedStatement nodes or any node that has
* NodeEmitFlags.NoComments.
*
* @param node A Node.
*/
function shouldSkipCommentsForNode(node: Node) {
return isNotEmittedStatement(node)
|| (getNodeEmitFlags(node) & NodeEmitFlags.NoComments) !== 0;
}
function shouldIgnoreSourceMapForNode(node: Node) {
return isNotEmittedOrPartiallyEmittedNode(node)
/**
* Determines whether to skip source map emit for a node.
*
* We do not emit source maps for NotEmittedStatement nodes or any node that
* has NodeEmitFlags.NoSourceMap.
*
* @param node A Node.
*/
function shouldSkipSourceMapForNode(node: Node) {
return isNotEmittedStatement(node)
|| (getNodeEmitFlags(node) & NodeEmitFlags.NoSourceMap) !== 0;
}
function shouldIgnoreSourceMapForChildren(node: Node) {
/**
* Determines whether to skip source map emit for a node and its children.
*
* We do not emit source maps for a node that has NodeEmitFlags.NoNestedSourceMaps.
*/
function shouldSkipSourceMapForChildren(node: Node) {
return (getNodeEmitFlags(node) & NodeEmitFlags.NoNestedSourceMaps) !== 0;
}
@@ -1064,7 +1086,6 @@ const _super = (function (geti, seti) {
emitDecorators(node, node.decorators);
emitModifiers(node, node.modifiers);
emitSignatureAndBody(node, emitArrowFunctionHead);
}
function emitArrowFunctionHead(node: ArrowFunction) {
@@ -1095,7 +1116,7 @@ const _super = (function (geti, seti) {
}
function emitPrefixUnaryExpression(node: PrefixUnaryExpression) {
writeToken(node.operator);
writeTokenText(node.operator);
if (shouldEmitWhitespaceBeforeOperand(node)) {
write(" ");
}
@@ -1123,7 +1144,7 @@ const _super = (function (geti, seti) {
function emitPostfixUnaryExpression(node: PostfixUnaryExpression) {
emitExpression(node.operand);
writeToken(node.operator);
writeTokenText(node.operator);
}
function emitBinaryExpression(node: BinaryExpression) {
@@ -1375,7 +1396,8 @@ const _super = (function (geti, seti) {
}
function emitDebuggerStatement(node: DebuggerStatement) {
write("debugger;");
writeToken(SyntaxKind.DebuggerKeyword, node.pos);
write(";");
}
//
@@ -1417,10 +1439,7 @@ const _super = (function (geti, seti) {
tempFlags = 0;
startLexicalEnvironment();
emitSignatureHead(node);
write(" {");
emitBlockFunctionBody(node, body);
write("}");
emitBlockFunctionBodyAndEndLexicalEnvironment(node, body);
if (indentedFlag) {
decreaseIndent();
}
@@ -1484,10 +1503,12 @@ const _super = (function (geti, seti) {
return true;
}
function emitBlockFunctionBody(parentNode: Node, body: Block) {
function emitBlockFunctionBodyAndEndLexicalEnvironment(parentNode: Node, body: Block) {
write(" {");
const startingLine = writer.getLine();
increaseIndent();
emitDetachedComments(body.statements);
emitLeadingDetachedComments(body.statements, body, shouldSkipCommentsForNode);
// Emit all the prologue directives (like "use strict").
const statementOffset = emitPrologueDirectives(body.statements, /*startWithNewLine*/ true);
@@ -1504,13 +1525,9 @@ const _super = (function (geti, seti) {
const endingLine = writer.getLine();
emitLexicalEnvironment(endLexicalEnvironment(), /*newLine*/ startingLine !== endingLine);
// Do not emit leading comments if the body belongs to arrow expression
if (!body.original || isBlock(body.original)) {
const range = collapseRangeToEnd(body.statements);
emitLeadingComments(range, getLeadingComments(range));
}
emitTrailingDetachedComments(body.statements, body, shouldSkipCommentsForNode);
decreaseIndent();
writeToken(SyntaxKind.CloseBraceToken, body.statements.end);
}
function emitClassDeclaration(node: ClassDeclaration) {
@@ -1831,7 +1848,7 @@ const _super = (function (geti, seti) {
function emitHeritageClause(node: HeritageClause) {
write(" ");
writeToken(node.token);
writeTokenText(node.token);
write(" ");
emitList(node, node.types, ListFormat.HeritageClauseTypes);
}
@@ -1886,7 +1903,7 @@ const _super = (function (geti, seti) {
function emitSourceFile(node: SourceFile) {
writeLine();
emitShebang();
emitDetachedComments(node);
emitLeadingDetachedComments(node);
const statements = node.statements;
const statementOffset = emitPrologueDirectives(statements);
@@ -1904,7 +1921,7 @@ const _super = (function (geti, seti) {
tempFlags = savedTempFlags;
}
emitLeadingComments(node.endOfFileToken, getLeadingComments(node.endOfFileToken));
emitTrailingDetachedComments(node.statements);
}
// Transformation nodes
@@ -2284,10 +2301,10 @@ const _super = (function (geti, seti) {
}
}
function writeToken(token: SyntaxKind, pos?: number) {
const tokenStartPos = skipTrivia(currentText, pos);
function writeToken(token: SyntaxKind, tokenStartPos: number) {
tokenStartPos = skipTrivia(currentText, tokenStartPos);
emitPos(tokenStartPos);
const tokenEndPos = writeTokenText(token, pos);
const tokenEndPos = writeTokenText(token, tokenStartPos);
emitPos(tokenEndPos);
return tokenEndPos;
}
@@ -2300,9 +2317,9 @@ const _super = (function (geti, seti) {
function writeTokenNode(node: Node) {
if (node) {
emitStart(node, shouldIgnoreSourceMapForNode, shouldIgnoreSourceMapForChildren);
emitStart(node, shouldSkipSourceMapForNode, shouldSkipSourceMapForChildren);
writeTokenText(node.kind);
emitEnd(node, shouldIgnoreSourceMapForNode, shouldIgnoreSourceMapForChildren);
emitEnd(node, shouldSkipSourceMapForNode, shouldSkipSourceMapForChildren);
}
}
+77 -17
View File
@@ -156,6 +156,7 @@ namespace ts {
context.expressionSubstitution = substituteExpression;
let currentSourceFile: SourceFile;
let currentText: string;
let currentParent: Node;
let currentNode: Node;
let enclosingBlockScopeContainer: Node;
@@ -183,6 +184,7 @@ namespace ts {
function transformSourceFile(node: SourceFile) {
currentSourceFile = node;
currentText = node.text;
return visitNode(node, visitor, isSourceFile);
}
@@ -609,6 +611,8 @@ namespace ts {
if (node.name) {
enableSubstitutionsForBlockScopedBindings();
}
const closingBraceLocation = { pos: node.end - 1, end: node.end };
const baseTypeNode = getClassExtendsHeritageClauseElement(node);
const classFunction = createFunctionExpression(
/*asteriskToken*/ undefined,
@@ -624,9 +628,19 @@ namespace ts {
setNodeEmitFlags(classFunction, NodeEmitFlags.Indented);
}
// "inner" and "outer" below are added purely to preserve source map locations from
// the old emitter
const inner = createPartiallyEmittedExpression(classFunction);
inner.end = node.end;
setNodeEmitFlags(inner, NodeEmitFlags.NoComments);
const outer = createPartiallyEmittedExpression(inner);
outer.end = node.pos;
setNodeEmitFlags(outer, NodeEmitFlags.NoComments);
return createParen(
createCall(
classFunction,
outer,
baseTypeNode
? [visitNode(baseTypeNode.expression, visitor, isExpression)]
: []
@@ -646,9 +660,27 @@ namespace ts {
addExtendsHelperIfNeeded(statements, node, hasExtendsClause);
addConstructor(statements, node, hasExtendsClause);
addClassMembers(statements, node);
statements.push(createReturn(getDeclarationName(node)));
// Create a synthetic text range for the return statement.
const closingBraceLocation = createTokenRange(skipTrivia(currentText, node.members.end), SyntaxKind.CloseBraceToken);
const name = getDeclarationName(node);
// The following partially-emitted expression exists purely to align our sourcemap
// emit with the original emitter.
const outer = createPartiallyEmittedExpression(name);
outer.end = closingBraceLocation.end;
setNodeEmitFlags(outer, NodeEmitFlags.NoComments);
const statement = createReturn(outer);
statement.pos = closingBraceLocation.pos;
statements.push(statement);
setNodeEmitFlags(statement, NodeEmitFlags.NoComments);
addRange(statements, endLexicalEnvironment());
return createBlock(statements, /*location*/ undefined, /*multiLine*/ true);
const block = createBlock(createNodeArray(statements, /*location*/ node.members), /*location*/ undefined, /*multiLine*/ true);
setNodeEmitFlags(block, NodeEmitFlags.NoComments);
return block;
}
/**
@@ -684,8 +716,8 @@ namespace ts {
/*asteriskToken*/ undefined,
getDeclarationName(node),
transformConstructorParameters(constructor, hasSynthesizedSuper),
transformConstructorBody(constructor, hasExtendsClause, hasSynthesizedSuper),
/*location*/ constructor
transformConstructorBody(constructor, node, hasExtendsClause, hasSynthesizedSuper),
/*location*/ constructor || node
)
);
}
@@ -714,11 +746,12 @@ namespace ts {
* Transforms the body of a constructor declaration of a class.
*
* @param constructor The constructor for the class.
* @param node The node which contains the constructor.
* @param hasExtendsClause A value indicating whether the class has an `extends` clause.
* @param hasSynthesizedSuper A value indicating whether the constructor starts with a
* synthesized `super` call.
*/
function transformConstructorBody(constructor: ConstructorDeclaration, hasExtendsClause: boolean, hasSynthesizedSuper: boolean) {
function transformConstructorBody(constructor: ConstructorDeclaration, node: ClassDeclaration | ClassExpression, hasExtendsClause: boolean, hasSynthesizedSuper: boolean) {
const statements: Statement[] = [];
startLexicalEnvironment();
if (constructor) {
@@ -735,14 +768,20 @@ namespace ts {
}
addRange(statements, endLexicalEnvironment());
return createBlock(
const block = createBlock(
createNodeArray(
statements,
/*location*/ constructor ? constructor.body.statements : undefined
/*location*/ constructor ? constructor.body.statements : node.members
),
/*location*/ constructor ? constructor.body : undefined,
/*location*/ constructor ? constructor.body : node,
/*multiLine*/ true
);
if (!constructor) {
setNodeEmitFlags(block, NodeEmitFlags.NoComments);
}
return block;
}
function transformConstructorBodyWithSynthesizedSuper(node: ConstructorDeclaration) {
@@ -1073,16 +1112,24 @@ namespace ts {
* @param member The MethodDeclaration node.
*/
function transformClassMethodDeclarationToStatement(receiver: LeftHandSideExpression, member: MethodDeclaration) {
return createStatement(
const statement = createStatement(
createAssignment(
createMemberAccessForPropertyName(
receiver,
visitNode(member.name, visitor, isPropertyName)
visitNode(member.name, visitor, isPropertyName),
/*location*/ member.name
),
transformFunctionLikeToExpression(member, /*location*/ undefined, /*name*/ undefined)
transformFunctionLikeToExpression(member, /*location*/ member, /*name*/ undefined),
/*location*/ moveRangeEnd(member, -1)
),
/*location*/ member
);
// The location for the statement is used to emit comments only.
// No source map should be emitted for this statement to align with the
// old emitter.
setNodeEmitFlags(statement, NodeEmitFlags.NoSourceMap);
return statement;
}
/**
@@ -1092,9 +1139,16 @@ namespace ts {
* @param accessors The set of related get/set accessors.
*/
function transformAccessorsToStatement(receiver: LeftHandSideExpression, accessors: AllAccessorDeclarations): Statement {
return createStatement(
transformAccessorsToExpression(receiver, accessors)
const statement = createStatement(
transformAccessorsToExpression(receiver, accessors),
/*location*/ accessors.firstAccessor
);
// The location for the statement is used to emit source maps only.
// No comments should be emitted for this statement to align with the
// old emitter.
setNodeEmitFlags(statement, NodeEmitFlags.NoComments);
return statement;
}
/**
@@ -1118,7 +1172,7 @@ namespace ts {
configurable: true
},
/*preferNewLine*/ true,
/*location*/ firstAccessor,
/*location*/ undefined,
/*descriptorLocations*/ {
get: getAccessor,
set: setAccessor
@@ -1220,6 +1274,7 @@ namespace ts {
// addPrologueDirectives will simply put already-existing directives at the beginning of the target statement-array
statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false);
}
addCaptureThisForNodeIfNeeded(statements, node);
addDefaultValueAssignmentsIfNeeded(statements, node);
addRestParameterIfNeeded(statements, node, /*inConstructorWithSynthesizedSuper*/ false);
@@ -1240,7 +1295,12 @@ namespace ts {
}
else {
Debug.assert(node.kind === SyntaxKind.ArrowFunction);
statementsLocation = body;
// To align with the old emitter, we use a synthetic end position on the location
// for the statement list we synthesize when we down-level an arrow function with
// an expression function body. This prevents both comments and source maps from
// being emitted for the end position only.
statementsLocation = moveRangeEnd(body, -1);
const equalsGreaterThanToken = (<ArrowFunction>node).equalsGreaterThanToken;
if (!nodeIsSynthesized(equalsGreaterThanToken) && !nodeIsSynthesized(body)) {
@@ -1254,7 +1314,7 @@ namespace ts {
const expression = visitNode(body, visitor, isExpression);
if (expression) {
statements.push(createReturn(expression));
statements.push(createReturn(expression, /*location*/ statementsLocation));
}
}
+55 -4
View File
@@ -2943,12 +2943,63 @@ namespace ts {
}
}
export function collapseRangeToStart(range: TextRange) {
return range.pos === range.end ? range : { pos: range.pos, end: range.pos };
/**
* Creates a new TextRange from a provided range with a new end position.
*
* @param range A TextRange.
* @param end The new end position.
*/
export function moveRangeEnd(range: TextRange, end: number): TextRange {
return { pos: range.pos, end };
}
export function collapseRangeToEnd(range: TextRange) {
return range.pos === range.end ? range : { pos: range.end, end: range.end };
/**
* Creates a new TextRange from a provided range with a new start position.
*
* @param range A TextRange.
* @param pos The new Start position.
*/
export function moveRangePos(range: TextRange, pos: number): TextRange {
return { pos, end: range.end };
}
/**
* Determines whether a TextRange has the same start and end positions.
*
* @param range A TextRange.
*/
export function isCollapsedRange(range: TextRange) {
return range.pos === range.end;
}
/**
* Creates a new TextRange from a provided range with its end position collapsed to its
* start position.
*
* @param range A TextRange.
*/
export function collapseRangeToStart(range: TextRange): TextRange {
return isCollapsedRange(range) ? range : moveRangeEnd(range, range.pos);
}
/**
* Creates a new TextRange from a provided range with its start position collapsed to its
* end position.
*
* @param range A TextRange.
*/
export function collapseRangeToEnd(range: TextRange): TextRange {
return isCollapsedRange(range) ? range : moveRangePos(range, range.end);
}
/**
* Creates a new TextRange for a token at the provides start position.
*
* @param pos The start position.
* @param token The token.
*/
export function createTokenRange(pos: number, token: SyntaxKind): TextRange {
return { pos, end: pos + tokenToString(token).length };
}
export function rangeIsOnSingleLine(range: TextRange, sourceFile: SourceFile) {
@@ -3,7 +3,6 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(3,5): error TS232
Type '() => number | string | boolean' is not assignable to type '() => number | string'.
Type 'number | string | boolean' is not assignable to type 'number | string'.
Type 'boolean' is not assignable to type 'number | string'.
Type 'boolean' is not assignable to type 'string'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(15,1): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'.
tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(18,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]'.
Types of property '0' are incompatible.
@@ -34,7 +33,6 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS23
!!! error TS2322: Type '() => number | string | boolean' is not assignable to type '() => number | string'.
!!! error TS2322: Type 'number | string | boolean' is not assignable to type 'number | string'.
!!! error TS2322: Type 'boolean' is not assignable to type 'number | string'.
!!! error TS2322: Type 'boolean' is not assignable to type 'string'.
var numStrBoolTuple: [number, string, boolean] = [5, "foo", true];
var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5];
var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]];
@@ -45,6 +45,6 @@ var x = function (a) { return a.toString(); };
var x2 = function (a) { return a.toString(); }; // Like iWithCallSignatures
var x2 = function (a) { return a; }; // Like iWithCallSignatures2
// With call signatures of mismatching parameter type
var x3 = function (a) { return a.toString(); };
var x3 = function (a) { /*here a should be any*/ return a.toString(); };
// With call signature count mismatch
var x4 = function (a) { return a.toString(); };
var x4 = function (a) { /*here a should be any*/ return a.toString(); };
@@ -14,7 +14,6 @@ tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTyp
Types of property '0' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedBindingInitializerNegative.ts(26,14): error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'.
Type '"baz"' is not assignable to type '"bar"'.
==== tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTypedBindingInitializerNegative.ts (7 errors) ====
@@ -67,5 +66,4 @@ tests/cases/conformance/types/contextualTypes/methodDeclarations/contextuallyTyp
function h({ prop = "baz" }: StringUnion) {}
~~~~
!!! error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'.
!!! error TS2322: Type '"baz"' is not assignable to type '"bar"'.
@@ -1,7 +1,5 @@
tests/cases/conformance/types/contextualTypes/jsxAttributes/contextuallyTypedStringLiteralsInJsxAttributes01.tsx(16,15): error TS2322: Type '"f"' is not assignable to type '"A" | "B" | "C"'.
Type '"f"' is not assignable to type '"C"'.
tests/cases/conformance/types/contextualTypes/jsxAttributes/contextuallyTypedStringLiteralsInJsxAttributes01.tsx(17,15): error TS2322: Type '"f"' is not assignable to type '"A" | "B" | "C"'.
Type '"f"' is not assignable to type '"C"'.
==== tests/cases/conformance/types/contextualTypes/jsxAttributes/contextuallyTypedStringLiteralsInJsxAttributes01.tsx (2 errors) ====
@@ -23,8 +21,6 @@ tests/cases/conformance/types/contextualTypes/jsxAttributes/contextuallyTypedStr
<FooComponent foo={"f"} />;
~~~~~~~~~
!!! error TS2322: Type '"f"' is not assignable to type '"A" | "B" | "C"'.
!!! error TS2322: Type '"f"' is not assignable to type '"C"'.
<FooComponent foo="f" />;
~~~~~~~
!!! error TS2322: Type '"f"' is not assignable to type '"A" | "B" | "C"'.
!!! error TS2322: Type '"f"' is not assignable to type '"C"'.
!!! error TS2322: Type '"f"' is not assignable to type '"A" | "B" | "C"'.
@@ -7,7 +7,6 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
Type '() => number | string[][] | string' is not assignable to type '() => number | string[][]'.
Type 'number | string[][] | string' is not assignable to type 'number | string[][]'.
Type 'string' is not assignable to type 'number | string[][]'.
Type 'string' is not assignable to type 'string[][]'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(23,14): error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'.
@@ -29,7 +28,6 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(38,4): error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: number | string; }'.
Types of property 'b' are incompatible.
Type 'boolean' is not assignable to type 'number | string'.
Type 'boolean' is not assignable to type 'string'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(39,4): error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
Types of property '2' are incompatible.
Type 'boolean' is not assignable to type '[[any]]'.
@@ -75,7 +73,6 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
!!! error TS2345: Type '() => number | string[][] | string' is not assignable to type '() => number | string[][]'.
!!! error TS2345: Type 'number | string[][] | string' is not assignable to type 'number | string[][]'.
!!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'.
!!! error TS2345: Type 'string' is not assignable to type 'string[][]'.
// If the declaration includes an initializer expression (which is permitted only
@@ -137,7 +134,6 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(
!!! error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: number | string; }'.
!!! error TS2345: Types of property 'b' are incompatible.
!!! error TS2345: Type 'boolean' is not assignable to type 'number | string'.
!!! error TS2345: Type 'boolean' is not assignable to type 'string'.
c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]]
~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
@@ -1,7 +1,6 @@
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(11,13): error TS2370: A rest parameter must be of an array type.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(13,13): error TS2370: A rest parameter must be of an array type.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number | string'.
Type 'boolean' is not assignable to type 'string'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(21,7): error TS2304: Cannot find name 'array2'.
tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(22,4): error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'.
Types of property '2' are incompatible.
@@ -43,7 +42,6 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(
a1(1, 2, "hello", true); // Error, parameter type is (number|string)[]
~~~~
!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number | string'.
!!! error TS2345: Type 'boolean' is not assignable to type 'string'.
a1(...array2); // Error parameter type is (number|string)[]
~~~~~~
!!! error TS2304: Cannot find name 'array2'.
@@ -1,7 +1,6 @@
tests/cases/compiler/errorMessagesIntersectionTypes02.ts(14,5): error TS2322: Type '{ fooProp: string; } & Bar' is not assignable to type 'FooBar'.
Types of property 'fooProp' are incompatible.
Type 'string' is not assignable to type '"hello" | "world"'.
Type 'string' is not assignable to type '"world"'.
==== tests/cases/compiler/errorMessagesIntersectionTypes02.ts (1 errors) ====
@@ -23,6 +22,5 @@ tests/cases/compiler/errorMessagesIntersectionTypes02.ts(14,5): error TS2322: Ty
!!! error TS2322: Type '{ fooProp: string; } & Bar' is not assignable to type 'FooBar'.
!!! error TS2322: Types of property 'fooProp' are incompatible.
!!! error TS2322: Type 'string' is not assignable to type '"hello" | "world"'.
!!! error TS2322: Type 'string' is not assignable to type '"world"'.
fooProp: "frizzlebizzle"
});
@@ -3,7 +3,6 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup
Type '() => string | number | boolean' is not assignable to type '() => string | number'.
Type 'string | number | boolean' is not assignable to type 'string | number'.
Type 'boolean' is not assignable to type 'string | number'.
Type 'boolean' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(14,1): error TS2322: Type '{ a: string; }' is not assignable to type 'string | number'.
Type '{ a: string; }' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(22,1): error TS2322: Type '[number, string]' is not assignable to type '[string, number]'.
@@ -35,7 +34,6 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup
!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => string | number'.
!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'string | number'.
!!! error TS2322: Type 'boolean' is not assignable to type 'string | number'.
!!! error TS2322: Type 'boolean' is not assignable to type 'number'.
var e3 = i1.tuple1[2]; // {}
i1.tuple1[3] = { a: "string" };
~~~~~~~~~~~~
@@ -1,12 +1,10 @@
tests/cases/conformance/es6/spread/iteratorSpreadInCall6.ts(1,28): error TS2345: Argument of type 'string' is not assignable to parameter of type 'symbol | number'.
Type 'string' is not assignable to type 'number'.
==== tests/cases/conformance/es6/spread/iteratorSpreadInCall6.ts (1 errors) ====
foo(...new SymbolIterator, ...new StringIterator);
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'symbol | number'.
!!! error TS2345: Type 'string' is not assignable to type 'number'.
function foo(...s: (symbol | number)[]) { }
class SymbolIterator {
@@ -4,15 +4,10 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(40,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(41,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(44,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
Type 'string' is not assignable to type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(45,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
Type 'string' is not assignable to type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(46,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
Type 'string' is not assignable to type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(47,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
Type 'string' is not assignable to type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(48,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
Type 'string' is not assignable to type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(55,43): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(57,52): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(58,43): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'.
@@ -26,9 +21,7 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(88,43): error TS2345: Argument of type '"Hello"' is not assignable to parameter of type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(89,52): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(93,5): error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'.
Type 'string' is not assignable to type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(97,5): error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'.
Type 'string' is not assignable to type '"World"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(100,25): error TS2345: Argument of type '"Hello" | "World"' is not assignable to parameter of type '"Hello"'.
Type '"World"' is not assignable to type '"Hello"'.
tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(104,25): error TS2345: Argument of type '"Hello" | "World"' is not assignable to parameter of type '"Hello"'.
@@ -92,23 +85,18 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0
a = takeReturnHelloWorld(a);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
!!! error TS2345: Type 'string' is not assignable to type '"World"'.
b = takeReturnHelloWorld(b);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
!!! error TS2345: Type 'string' is not assignable to type '"World"'.
c = takeReturnHelloWorld(c);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
!!! error TS2345: Type 'string' is not assignable to type '"World"'.
d = takeReturnHelloWorld(d);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
!!! error TS2345: Type 'string' is not assignable to type '"World"'.
e = takeReturnHelloWorld(e);
~
!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'.
!!! error TS2345: Type 'string' is not assignable to type '"World"'.
}
namespace n2 {
@@ -178,14 +166,12 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0
a = takeReturnString(a);
~
!!! error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'.
!!! error TS2322: Type 'string' is not assignable to type '"World"'.
b = takeReturnString(b);
c = takeReturnString(c);
d = takeReturnString(d);
e = takeReturnString(e);
~
!!! error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'.
!!! error TS2322: Type 'string' is not assignable to type '"World"'.
// Passing these as arguments should cause an error.
a = takeReturnHello(a);