fix(49449): change error location when passing objects/arrays to an argument of type (#49593)

This commit is contained in:
Oleksandr T 2022-06-22 20:06:01 +03:00 committed by GitHub
parent 71b5bdf980
commit 8636adbbb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 2 deletions

View File

@ -17840,7 +17840,7 @@ namespace ts {
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } | undefined
) {
if (target.flags & TypeFlags.Primitive) return false;
if (target.flags & (TypeFlags.Primitive | TypeFlags.Never)) return false;
if (isTupleLikeType(source)) {
return elaborateElementwise(generateLimitedTupleElements(node, target), source, target, relation, containingMessageChain, errorOutputContainer);
}
@ -17893,7 +17893,7 @@ namespace ts {
containingMessageChain: (() => DiagnosticMessageChain | undefined) | undefined,
errorOutputContainer: { errors?: Diagnostic[], skipLogging?: boolean } | undefined
) {
if (target.flags & TypeFlags.Primitive) return false;
if (target.flags & (TypeFlags.Primitive | TypeFlags.Never)) return false;
return elaborateElementwise(generateObjectLiteralElements(node), source, target, relation, containingMessageChain, errorOutputContainer);
}

View File

@ -0,0 +1,14 @@
tests/cases/compiler/assignmentCompatability46.ts(3,4): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'never'.
tests/cases/compiler/assignmentCompatability46.ts(4,4): error TS2345: Argument of type '{ a: number; b: number; }' is not assignable to parameter of type 'never'.
==== tests/cases/compiler/assignmentCompatability46.ts (2 errors) ====
declare function fn(x: never): void;
fn([1, 2, 3])
~~~~~~~~~
!!! error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'never'.
fn({ a: 1, b: 2 })
~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ a: number; b: number; }' is not assignable to parameter of type 'never'.

View File

@ -0,0 +1,10 @@
//// [assignmentCompatability46.ts]
declare function fn(x: never): void;
fn([1, 2, 3])
fn({ a: 1, b: 2 })
//// [assignmentCompatability46.js]
fn([1, 2, 3]);
fn({ a: 1, b: 2 });

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/assignmentCompatability46.ts ===
declare function fn(x: never): void;
>fn : Symbol(fn, Decl(assignmentCompatability46.ts, 0, 0))
>x : Symbol(x, Decl(assignmentCompatability46.ts, 0, 20))
fn([1, 2, 3])
>fn : Symbol(fn, Decl(assignmentCompatability46.ts, 0, 0))
fn({ a: 1, b: 2 })
>fn : Symbol(fn, Decl(assignmentCompatability46.ts, 0, 0))
>a : Symbol(a, Decl(assignmentCompatability46.ts, 3, 4))
>b : Symbol(b, Decl(assignmentCompatability46.ts, 3, 10))

View File

@ -0,0 +1,22 @@
=== tests/cases/compiler/assignmentCompatability46.ts ===
declare function fn(x: never): void;
>fn : (x: never) => void
>x : never
fn([1, 2, 3])
>fn([1, 2, 3]) : void
>fn : (x: never) => void
>[1, 2, 3] : number[]
>1 : 1
>2 : 2
>3 : 3
fn({ a: 1, b: 2 })
>fn({ a: 1, b: 2 }) : void
>fn : (x: never) => void
>{ a: 1, b: 2 } : { a: number; b: number; }
>a : number
>1 : 1
>b : number
>2 : 2

View File

@ -0,0 +1,4 @@
declare function fn(x: never): void;
fn([1, 2, 3])
fn({ a: 1, b: 2 })