Report assignability errors on the return/yield keywords (#52943)

This commit is contained in:
Mateusz Burzyński authored and GitHub committed 2023-03-06 16:50:47 -08:00
1 parent 5240f060b8
commit 967911c389
53 files changed
+92 -90

No files matched your search

+9 -2
View File
@@ -2179,13 +2179,14 @@ function getErrorSpanForArrowFunction(sourceFile: SourceFile, node: ArrowFunctio
export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpan {
let errorNode: Node | undefined = node;
switch (node.kind) {
case SyntaxKind.SourceFile:
case SyntaxKind.SourceFile: {
const pos = skipTrivia(sourceFile.text, 0, /*stopAfterLineBreak*/ false);
if (pos === sourceFile.text.length) {
// file is empty - return span for the beginning of the file
return createTextSpan(0, 0);
}
return getSpanOfTokenAtPosition(sourceFile, pos);
}
// This list is a work in progress. Add missing node kinds to improve their error
// spans.
case SyntaxKind.VariableDeclaration:
@@ -2210,10 +2211,16 @@ export function getErrorSpanForNode(sourceFile: SourceFile, node: Node): TextSpa
case SyntaxKind.ArrowFunction:
return getErrorSpanForArrowFunction(sourceFile, node as ArrowFunction);
case SyntaxKind.CaseClause:
case SyntaxKind.DefaultClause:
case SyntaxKind.DefaultClause: {
const start = skipTrivia(sourceFile.text, (node as CaseOrDefaultClause).pos);
const end = (node as CaseOrDefaultClause).statements.length > 0 ? (node as CaseOrDefaultClause).statements[0].pos : (node as CaseOrDefaultClause).end;
return createTextSpanFromBounds(start, end);
}
case SyntaxKind.ReturnStatement:
case SyntaxKind.YieldExpression: {
const pos = skipTrivia(sourceFile.text, (node as ReturnStatement | YieldExpression).pos);
return getSpanOfTokenAtPosition(sourceFile, pos);
}
}
if (errorNode === undefined) {
@@ -8,11 +8,11 @@ tests/cases/compiler/accessors_spec_section-4.5_error-cases.ts(11,51): error TS2
class LanguageSpec_section_4_5_error_cases {
public set AnnotatedSetter_SetterFirst(a: number) { }
public get AnnotatedSetter_SetterFirst() { return ""; }
~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
public get AnnotatedSetter_SetterLast() { return ""; }
~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
public set AnnotatedSetter_SetterLast(a: number) { }
@@ -28,7 +28,7 @@ tests/cases/conformance/async/es2017/asyncArrowFunction/file.js(19,3): error TS2
!!! error TS1064: The return type of an async function or method must be the global Promise<T> type. Did you mean to write 'Promise<string>'?
const c = async () => {
return 0
~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
}
@@ -7,22 +7,17 @@ tests/cases/compiler/baseConstraintOfDecorator.ts(12,18): error TS2545: A mixin
==== tests/cases/compiler/baseConstraintOfDecorator.ts (3 errors) ====
export function classExtender<TFunction>(superClass: TFunction, _instanceModifier: (instance: any, args: any[]) => void): TFunction {
return class decoratorFunc extends superClass {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'typeof decoratorFunc' is not assignable to type 'TFunction'.
!!! error TS2322: 'TFunction' could be instantiated with an arbitrary type which could be unrelated to 'typeof decoratorFunc'.
~~~~~~~~~~
!!! error TS2507: Type 'TFunction' is not a constructor function type.
!!! related TS2735 tests/cases/compiler/baseConstraintOfDecorator.ts:1:31: Did you mean for 'TFunction' to be constrained to type 'new (...args: any[]) => unknown'?
constructor(...args: any[]) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
super(...args);
~~~~~~~~~~~~~~~~~~~~~~~~~~~
_instanceModifier(this, args);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
~~~~~~~~~
};
~~~~~~
!!! error TS2322: Type 'typeof decoratorFunc' is not assignable to type 'TFunction'.
!!! error TS2322: 'TFunction' could be instantiated with an arbitrary type which could be unrelated to 'typeof decoratorFunc'.
}
class MyClass { private x; }
@@ -12,7 +12,7 @@ tests/cases/conformance/jsdoc/returns.js(13,5): error TS2322: Type 'number | boo
*/
function f() {
return 5;
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
}
@@ -21,7 +21,7 @@ tests/cases/conformance/jsdoc/returns.js(13,5): error TS2322: Type 'number | boo
*/
function f1() {
return 5 || true;
~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number | boolean' is not assignable to type 'string | number'.
!!! error TS2322: Type 'boolean' is not assignable to type 'string | number'.
}
@@ -13,7 +13,7 @@ tests/cases/conformance/jsdoc/test.js(34,5): error TS2322: Type '1 | 2' is not a
// all 6 should error on return statement/expression
/** @type {(x: number) => string} */
function h(x) { return x }
~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
/** @type {(x: number) => string} */
var f = x => x
@@ -21,12 +21,12 @@ tests/cases/conformance/jsdoc/test.js(34,5): error TS2322: Type '1 | 2' is not a
!!! error TS2322: Type 'number' is not assignable to type 'string'.
/** @type {(x: number) => string} */
var g = function (x) { return x }
~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
/** @type {{ (x: number): string }} */
function i(x) { return x }
~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
/** @type {{ (x: number): string }} */
var j = x => x
@@ -34,7 +34,7 @@ tests/cases/conformance/jsdoc/test.js(34,5): error TS2322: Type '1 | 2' is not a
!!! error TS2322: Type 'number' is not assignable to type 'string'.
/** @type {{ (x: number): string }} */
var k = function (x) { return x }
~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
@@ -19,7 +19,7 @@ tests/cases/conformance/jsdoc/0.js(22,22): error TS2345: Argument of type 'strin
/** @type {function(number): number} */
method1(n1) {
return "42";
~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
},
/** @type {function(number): number} */
@@ -53,7 +53,7 @@ tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.t
export function makeNewChannel<T extends ChannelType>(type: T): NewChannel<ChannelOfType<T>> {
const localChannelId = `blahblahblah`;
return { type, localChannelId };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type '{ type: T; localChannelId: string; }' is not assignable to type 'NewChannel<ChannelOfType<T, TextChannel> | ChannelOfType<T, EmailChannel>>'.
!!! error TS2322: Type '{ type: T; localChannelId: string; }' is not assignable to type 'Pick<ChannelOfType<T, TextChannel> | ChannelOfType<T, EmailChannel>, "type">'.
!!! error TS2322: Types of property 'type' are incompatible.
@@ -129,7 +129,7 @@ tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts(116,3): error T
function f3<Q extends (arg: any) => any>(x: Q): InferBecauseWhyNot<Q> {
return x;
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'Q' is not assignable to type 'InferBecauseWhyNot<Q>'.
!!! error TS2322: Type '(arg: any) => any' is not assignable to type 'InferBecauseWhyNot<Q>'.
}
@@ -142,7 +142,7 @@ tests/cases/compiler/conditionalTypeAssignabilityWhenDeferred.ts(116,3): error T
x: Q
): InferBecauseWhyNotDistributive<Q> {
return x; // should fail
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'Q' is not assignable to type 'InferBecauseWhyNotDistributive<Q>'.
!!! error TS2322: Type '(arg: any) => any' is not assignable to type 'InferBecauseWhyNotDistributive<Q>'.
}
@@ -27,7 +27,7 @@ tests/cases/conformance/constEnums/constEnumPropertyAccess1.ts(25,9): error TS23
[G.A]() { }
get [G.B]() {
return true;
~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'boolean' is not assignable to type 'number'.
}
set [G.B](x: number) { }
@@ -6,9 +6,9 @@ tests/cases/compiler/constructorReturnsInvalidType.ts(3,9): error TS2409: Return
class X {
constructor() {
return 1;
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'X'.
~~~~~~~~~
~~~~~~
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
}
foo() { }
@@ -18,9 +18,9 @@ tests/cases/conformance/classes/constructorDeclarations/constructorWithAssignabl
x: number;
constructor() {
return 1; // error
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'D'.
~~~~~~~~~
~~~~~~
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
}
}
@@ -36,7 +36,7 @@ tests/cases/conformance/classes/constructorDeclarations/constructorWithAssignabl
x: T;
constructor() {
return { x: 1 }; // error
~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
~
!!! error TS2322: Type 'number' is not assignable to type 'T'.
@@ -38,12 +38,12 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC
class E<T extends string> extends D {
x: T;
get X(): T { return ''; } // error
~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'T'.
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
foo(): T {
return ''; // error
~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'T'.
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
}
@@ -6,7 +6,7 @@ tests/cases/compiler/doNotElaborateAssignabilityToTypeParameters.ts(3,3): error
async function foo<T>(x: T): Promise<T> {
let yaddable = await getXOrYadda(x);
return yaddable;
~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'Yadda | Awaited<T>' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Yadda | Awaited<T>'.
}
@@ -45,7 +45,7 @@ tests/cases/compiler/emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts(4
const result = foos == null ? {} : mapValues(foos, f => f.foo);
// This line _should_ fail, because `result` is not the right type.
return result;
~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'Dictionary<string>' is not assignable to type 'Record<string, Bar>'.
!!! error TS2322: 'string' index signatures are incompatible.
!!! error TS2322: Type 'string' is not assignable to type 'Bar'.
@@ -46,7 +46,7 @@ tests/cases/compiler/emptyObjectNotSubtypeOfIndexSignatureContainingObject2.ts(4
const result = foos == null ? {} : mapValues(foos, f => f.foo);
// This line _should_ fail, because `result` is not the right type.
return result;
~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'Dictionary<string>' is not assignable to type 'Record<string, Bar>'.
!!! error TS2322: 'string' index signatures are incompatible.
!!! error TS2322: Type 'string' is not assignable to type 'Bar'.
@@ -24,7 +24,7 @@ tests/cases/conformance/jsdoc/foo.js(45,18): error TS2534: A function returning
/** @type {FunctionReturningPromise} */
async function testPromise2() {
return "asd";
~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
}
@@ -56,7 +56,7 @@ tests/cases/conformance/jsdoc/foo.js(45,18): error TS2534: A function returning
/** @type {FunctionReturningNever} */
async function testNever2() {
return "asd";
~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'never'.
}
@@ -9,7 +9,7 @@ tests/cases/compiler/bar.ts(4,31): error TS2523: 'yield' expressions cannot be u
}
export function* foo2({ foo = yield "a" }) {
~~~~~~~~~
~~~~~
!!! error TS2523: 'yield' expressions cannot be used in a parameter initializer.
}
@@ -17,7 +17,7 @@ tests/cases/conformance/generators/generatorExplicitReturnType.ts(16,11): error
~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
return 10; // error
~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'boolean'.
}
@@ -36,7 +36,7 @@ tests/cases/conformance/generators/generatorReturnContextualType.ts(34,3): error
async function* f4(): AsyncGenerator<any, { x: 'x' }, any> {
const ret = { x: 'x' };
return Promise.resolve(ret); // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type '{ x: string; }' is not assignable to type '{ x: "x"; }'.
!!! error TS2322: Types of property 'x' are incompatible.
!!! error TS2322: Type 'string' is not assignable to type '"x"'.
@@ -45,7 +45,7 @@ tests/cases/conformance/generators/generatorReturnContextualType.ts(34,3): error
async function* g4(): AsyncIterator<any, { x: 'x' }, any> {
const ret = { x: 'x' };
return Promise.resolve(ret); // Error
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type '{ x: string; }' is not assignable to type '{ x: "x"; }'.
!!! error TS2322: Types of property 'x' are incompatible.
!!! error TS2322: Type 'string' is not assignable to type '"x"'.
@@ -74,7 +74,7 @@ tests/cases/conformance/generators/generatorReturnTypeInference.ts(72,15): error
function* g204() { // Generator<number, void, any>
const x = f2(yield 1);
~~~~~~~
~~~~~
!!! error TS7057: 'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation.
}
@@ -86,7 +86,7 @@ tests/cases/conformance/generators/generatorReturnTypeInferenceNonStrict.ts(131,
function* g204() { // Generator<number, void, any>
const x = f2(yield 1);
~~~~~~~
~~~~~
!!! error TS7057: 'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation.
}
@@ -10,7 +10,7 @@ tests/cases/conformance/expressions/contextualTyping/getSetAccessorContextualTyp
set X(x: number) { }
get X() {
return "string"; // Error; get contextual type by set accessor parameter type annotation
~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
}
@@ -16,9 +16,9 @@ tests/cases/compiler/main.ts(4,5): error TS2343: This syntax requires an importe
await 1;
yield 2;
yield* [3];
~~~~~~~~~~
~~~~~
!!! error TS2343: This syntax requires an imported helper named '__asyncDelegator' which does not exist in 'tslib'. Consider upgrading your version of 'tslib'.
~~~~~~~~~~
~~~~~
!!! error TS2343: This syntax requires an imported helper named '__asyncValues' which does not exist in 'tslib'. Consider upgrading your version of 'tslib'.
}
@@ -15,7 +15,7 @@ tests/cases/compiler/inferSetterParamType.ts(13,9): error TS2322: Type 'number'
get bar() {
return 0; // should be an error - can't coerce infered return type to match setter annotated type
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
}
set bar(n:string) {
@@ -31,11 +31,11 @@ tests/cases/conformance/statements/returnStatements/invalidReturnStatements.ts(1
name: string;
}
function fn10(): D { return { id: 12 }; }
~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2739: Type '{ id: number; }' is missing the following properties from type 'D': name, dispose
function fn11(): D { return new C(); }
~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2741: Property 'name' is missing in type 'C' but required in type 'D'.
!!! related TS2728 tests/cases/conformance/statements/returnStatements/invalidReturnStatements.ts:14:5: 'name' is declared here.
@@ -195,7 +195,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS23
function get123<K extends keyof Type>(): Type[K] {
return 123; // Error
~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type '123' is not assignable to type 'Type[K]'.
!!! error TS2322: Type 'number' is not assignable to type 'never'.
}
@@ -32,7 +32,7 @@ tests/cases/compiler/matchReturnTypeInAllBranches.ts(30,13): error TS2322: Type
else
{
return 12345;
~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'boolean'.
}
}
@@ -66,7 +66,7 @@ tests/cases/compiler/narrowByEquality.ts(55,9): error TS2322: Type 'string | num
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
return level;
~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string | number' is not assignable to type 'number'.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
}
@@ -42,13 +42,13 @@ tests/cases/conformance/types/never/neverTypeErrors1.ts(24,17): error TS2407: Th
function f2(): never {
return;
~~~~~~~
~~~~~~
!!! error TS2322: Type 'undefined' is not assignable to type 'never'.
}
function f3(): never {
return 1;
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'never'.
}
@@ -42,13 +42,13 @@ tests/cases/conformance/types/never/neverTypeErrors2.ts(24,17): error TS2407: Th
function f2(): never {
return;
~~~~~~~
~~~~~~
!!! error TS2322: Type 'undefined' is not assignable to type 'never'.
}
function f3(): never {
return 1;
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'never'.
}
@@ -5,7 +5,7 @@ tests/cases/compiler/noImplicitReturnsWithoutReturnExpression.ts(22,9): error TS
==== tests/cases/compiler/noImplicitReturnsWithoutReturnExpression.ts (2 errors) ====
function isMissingReturnExpression(): number {
return;
~~~~~~~
~~~~~~
!!! error TS7030: Not all code paths return a value.
}
@@ -27,7 +27,7 @@ tests/cases/compiler/noImplicitReturnsWithoutReturnExpression.ts(22,9): error TS
}
else {
return;
~~~~~~~
~~~~~~
!!! error TS7030: Not all code paths return a value.
}
}
@@ -143,7 +143,7 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(99,11): error TS232
function generic1<T extends { [s: string]: boolean }>(arg: T): boolean {
// Should error
return arg["blah"];
~~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
}
function generic2<T extends { [s: string]: boolean }>(arg: T): boolean {
@@ -153,7 +153,7 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(99,11): error TS232
function generic3<T extends string>(arg: T): boolean {
// Should error
return strMap[arg];
~~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
}
@@ -25,7 +25,7 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveInFunction.ts(17,5): erro
function returnError(): object {
var ret = 123;
return ret; // expect error
~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'object'.
}
@@ -5,7 +5,7 @@ tests/cases/compiler/numberToString.ts(9,4): error TS2345: Argument of type 'num
==== tests/cases/compiler/numberToString.ts (2 errors) ====
function f1(n:number):string {
return n; // error return type mismatch
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
}
@@ -271,7 +271,7 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(50,5):
~
!!! error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type
var g2 = { get a() { return 4; }, set a(n: string) { } };
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
var g3 = { get a(): number { return undefined; }, set a(n: string) { } };
~
@@ -47,7 +47,7 @@ tests/cases/compiler/parseInvalidNullableTypes.ts(24,8): error TS17019: '?' at t
~~~~~~~
!!! error TS17020: '?' at the start of a type is not valid TypeScript syntax. Did you mean to write 'string | null | undefined'?
return true;
~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'boolean' is not assignable to type 'string'.
}
@@ -6,7 +6,7 @@ tests/cases/compiler/promiseEmptyTupleNoException.ts(3,3): error TS2322: Type 'a
export async function get(): Promise<[]> {
let emails = [];
return emails;
~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'any[]' is not assignable to type '[]'.
!!! error TS2322: Target allows only 0 element(s) but source may have more.
}
@@ -51,7 +51,7 @@ tests/cases/conformance/types/typeParameters/typeParameterLists/propertyAccessOn
foo: <U extends T, T extends A>(x: U): U => {
var a = x['foo'](); // should be string
return a + x.notHere();
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'U'.
!!! error TS2322: 'U' could be instantiated with an arbitrary type which could be unrelated to 'string'.
~~~~~~~
@@ -231,7 +231,7 @@ tests/cases/compiler/recursiveConditionalTypes.ts(169,5): error TS2322: Type 'nu
function foo2<T extends unknown[]>(value: T): Enumerate<T['length']> {
return value.length; // Error
~~~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'Enumerate<T["length"]>'.
}
@@ -22,7 +22,7 @@ tests/cases/compiler/recursiveFunctionTypes.ts(43,4): error TS2769: No overload
==== tests/cases/compiler/recursiveFunctionTypes.ts (13 errors) ====
function fn(): typeof fn { return 1; }
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type '() => typeof fn'.
var x: number = fn; // error
@@ -22,9 +22,9 @@ tests/cases/compiler/returnInConstructor1.ts(55,9): error TS2409: Return type of
foo() { }
constructor() {
return 1; // error
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'number' is not assignable to type 'B'.
~~~~~~~~~
~~~~~~
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
}
}
@@ -40,9 +40,9 @@ tests/cases/compiler/returnInConstructor1.ts(55,9): error TS2409: Return type of
foo() { }
constructor() {
return "test"; // error
~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'D'.
~~~~~~~~~~~~~~
~~~~~~
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
}
}
@@ -58,7 +58,7 @@ tests/cases/compiler/returnInConstructor1.ts(55,9): error TS2409: Return type of
public foo: string;
constructor() {
return { foo: 1 }; //error
~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
~~~
!!! error TS2322: Type 'number' is not assignable to type 'string'.
@@ -79,11 +79,11 @@ tests/cases/compiler/returnInConstructor1.ts(55,9): error TS2409: Return type of
constructor() {
super();
return new G(); //error
~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'G' is not assignable to type 'H'.
!!! error TS2322: Types of property 'foo' are incompatible.
!!! error TS2322: Type '() => void' is not assignable to type 'string'.
~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
}
}
@@ -5,7 +5,7 @@ tests/cases/compiler/returnValueInSetter.ts(3,9): error TS2408: Setters cannot r
class f {
set x(value) {
return null; // Should be an error
~~~~~~~~~~~~
~~~~~~
!!! error TS2408: Setters cannot return a value.
}
}
@@ -7,12 +7,12 @@ tests/cases/compiler/setterWithReturn.ts(7,13): error TS2408: Setters cannot ret
public set p1(arg1) {
if (true) {
return arg1;
~~~~~~~~~~~~
~~~~~~
!!! error TS2408: Setters cannot return a value.
}
else {
return 0;
~~~~~~~~~
~~~~~~
!!! error TS2408: Setters cannot return a value.
}
}
@@ -6,7 +6,7 @@ tests/cases/conformance/es6/Symbols/symbolProperty47.ts(11,1): error TS2322: Typ
class C {
get [Symbol.hasInstance]() {
return "";
~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
}
// Should take a string
@@ -5,7 +5,7 @@ tests/cases/compiler/targetTypeVoidFunc.ts(2,5): error TS2322: Type '() => void'
==== tests/cases/compiler/targetTypeVoidFunc.ts (1 errors) ====
function f1(): { new (): number; } {
return function () { return; }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type '() => void' is not assignable to type 'new () => number'.
!!! error TS2322: Type '() => void' provides no match for the signature 'new (): number'.
};
@@ -82,7 +82,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,54
function hasANonBooleanReturnStatement(x): x is A {
return '';
~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'boolean'.
}
@@ -247,9 +247,9 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,54
~~~~~~~
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
return true;
~~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'boolean' is not assignable to type 'D'.
~~~~~~~~~~~~
~~~~~~
!!! error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
}
get m1(p1: A): p1 is C {
@@ -261,7 +261,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,54
~~~~~~~
!!! error TS1228: A type predicate is only allowed in return type position for functions and methods.
return true;
~~~~~~~~~~~~
~~~~~~
!!! error TS2408: Setters cannot return a value.
}
}
@@ -21,7 +21,7 @@ tests/cases/compiler/typeParameterAssignmentCompat1.ts(17,9): error TS2322: Type
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'U'.
!!! related TS2208 tests/cases/compiler/typeParameterAssignmentCompat1.ts:5:15: This type parameter might need an `extends T` constraint.
return x;
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'Foo<T>' is not assignable to type 'Foo<U>'.
}
@@ -33,7 +33,7 @@ tests/cases/compiler/typeParameterAssignmentCompat1.ts(17,9): error TS2322: Type
~
!!! error TS2322: Type 'Foo<U>' is not assignable to type 'Foo<T>'.
return x;
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'Foo<T>' is not assignable to type 'Foo<U>'.
}
}
@@ -7,7 +7,7 @@ tests/cases/compiler/typeParameterHasSelfAsConstraint.ts(2,5): error TS2322: Typ
~
!!! error TS2313: Type parameter 'T' has a circular constraint.
return x;
~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'T' is not assignable to type 'number'.
!!! related TS2208 tests/cases/compiler/typeParameterHasSelfAsConstraint.ts:1:14: This type parameter might need an `extends number` constraint.
}
@@ -264,7 +264,7 @@ tests/cases/conformance/types/unknown/unknownType1.ts(181,5): error TS2322: Type
function oops<T extends unknown>(arg: T): {} {
return arg; // Error
~~~~~~~~~~~
~~~~~~
!!! error TS2322: Type 'T' is not assignable to type '{}'.
}
@@ -219,7 +219,7 @@ tests/cases/conformance/types/unknown/unknownType2.ts(216,13): error TS2322: Typ
case 'no':
case 'maybe':
return x; // error
~~~~~~~~~
~~~~~~
!!! error TS2322: Type '"yes" | "no" | "maybe"' is not assignable to type 'SomeResponse'.
!!! error TS2322: Type '"maybe"' is not assignable to type 'SomeResponse'.
default:
@@ -8,7 +8,7 @@ tests/cases/conformance/es6/yieldExpressions/bug25149.js(4,13): error TS7057: 'y
var o
while (true) {
o = yield o
~~~~~~~
~~~~~
!!! error TS7057: 'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation.
}
}
@@ -6,7 +6,7 @@ tests/cases/compiler/yieldExpressionInFlowLoop.ts(4,18): error TS7057: 'yield' e
let result;
while (1) {
result = yield result;
~~~~~~~~~~~~
~~~~~
!!! error TS7057: 'yield' expression implicitly results in an 'any' type because its containing generator lacks a return-type annotation.
}
}