Skip to content

Commit 879d765

Browse files
Fix error display on literal types (microsoft#429)
1 parent a253704 commit 879d765

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

internal/checker/relater.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4699,24 +4699,24 @@ func (r *Relater) reportRelationError(message *diagnostics.Message, source *Type
46994699
case diagnostics.Excessive_complexity_comparing_types_0_and_1,
47004700
diagnostics.Excessive_stack_depth_comparing_types_0_and_1,
47014701
diagnostics.The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1:
4702-
if r.chainArgsMatch(sourceType, targetType) {
4702+
if r.chainArgsMatch(generalizedSourceType, targetType) {
47034703
return
47044704
}
47054705
// Suppress if next message is a missing property message for source and target and we're not
47064706
// reporting on interface implementation
47074707
case diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2:
4708-
if !isInterfaceImplementationMessage(message) && r.chainArgsMatch(nil, sourceType, targetType) {
4708+
if !isInterfaceImplementationMessage(message) && r.chainArgsMatch(nil, generalizedSourceType, targetType) {
47094709
return
47104710
}
47114711
// Suppress if next message is a missing property message for source and target and we're not
47124712
// reporting on interface implementation
47134713
case diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more,
47144714
diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2:
4715-
if !isInterfaceImplementationMessage(message) && r.chainArgsMatch(sourceType, targetType) {
4715+
if !isInterfaceImplementationMessage(message) && r.chainArgsMatch(generalizedSourceType, targetType) {
47164716
return
47174717
}
47184718
}
4719-
r.reportError(message, sourceType, targetType)
4719+
r.reportError(message, generalizedSourceType, targetType)
47204720
}
47214721

47224722
func (r *Relater) reportError(message *diagnostics.Message, args ...any) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/src/bar.ts(1,7): error TS2322: Type '1' is not assignable to type 'string'.
2-
/src/foo.ts(1,7): error TS2322: Type '""' is not assignable to type 'number'.
1+
/src/bar.ts(1,7): error TS2322: Type 'number' is not assignable to type 'string'.
2+
/src/foo.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'.
33

44

55
==== /src/foo.ts (1 errors) ====
66
const x: number = "";
77
~
8-
!!! error TS2322: Type '""' is not assignable to type 'number'.
8+
!!! error TS2322: Type 'string' is not assignable to type 'number'.
99

1010
==== /src/bar.ts (1 errors) ====
1111
const y: string = 1;
1212
~
13-
!!! error TS2322: Type '1' is not assignable to type 'string'.
13+
!!! error TS2322: Type 'number' is not assignable to type 'string'.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
simpleTestSingleFile.ts(1,7): error TS2322: Type '""' is not assignable to type 'number'.
1+
simpleTestSingleFile.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'.
22

33

44
==== simpleTestSingleFile.ts (1 errors) ====
55
const x: number = "";
66
~
7-
!!! error TS2322: Type '""' is not assignable to type 'number'.
7+
!!! error TS2322: Type 'string' is not assignable to type 'number'.

testdata/baselines/reference/tscWatch/noEmit/semantic-errors.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ CompilerOptions::{
141141

142142

143143
Output::
144-
a.ts(1,7): error TS2322: Type '"hello"' is not assignable to type 'number'.
144+
a.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'.
145145

146146

147147
Found 1 error in a.ts:1
@@ -194,7 +194,7 @@ Output::
194194
Edit:: introduce error
195195

196196
Output::
197-
a.ts(1,7): error TS2322: Type '"hello"' is not assignable to type 'number'.
197+
a.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'.
198198

199199

200200
Found 1 error in a.ts:1
@@ -209,7 +209,7 @@ const a: number = "hello"
209209
Edit:: emit when error
210210

211211
Output::
212-
a.ts(1,7): error TS2322: Type '"hello"' is not assignable to type 'number'.
212+
a.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'.
213213

214214

215215
Found 1 error in a.ts:1
@@ -228,7 +228,7 @@ Found 1 error in a.ts:1
228228
Edit:: no emit run when error
229229

230230
Output::
231-
a.ts(1,7): error TS2322: Type '"hello"' is not assignable to type 'number'.
231+
a.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'.
232232

233233

234234
Found 1 error in a.ts:1

0 commit comments

Comments
 (0)