mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
fix(49449): change error location when passing objects/arrays to an argument of type (#49593)
This commit is contained in:
parent
71b5bdf980
commit
8636adbbb9
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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'.
|
||||
|
||||
10
tests/baselines/reference/assignmentCompatability46.js
Normal file
10
tests/baselines/reference/assignmentCompatability46.js
Normal 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 });
|
||||
13
tests/baselines/reference/assignmentCompatability46.symbols
Normal file
13
tests/baselines/reference/assignmentCompatability46.symbols
Normal 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))
|
||||
|
||||
22
tests/baselines/reference/assignmentCompatability46.types
Normal file
22
tests/baselines/reference/assignmentCompatability46.types
Normal 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
|
||||
|
||||
4
tests/cases/compiler/assignmentCompatability46.ts
Normal file
4
tests/cases/compiler/assignmentCompatability46.ts
Normal file
@ -0,0 +1,4 @@
|
||||
declare function fn(x: never): void;
|
||||
|
||||
fn([1, 2, 3])
|
||||
fn({ a: 1, b: 2 })
|
||||
Loading…
x
Reference in New Issue
Block a user