Skip to content

Commit b328a8f

Browse files
authored
Revert back to isObjectLiteralType check (#1764)
1 parent 206bc9c commit b328a8f

File tree

4 files changed

+176
-2
lines changed

4 files changed

+176
-2
lines changed

internal/checker/relater.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4153,7 +4153,7 @@ func (r *Relater) propertiesRelatedTo(source *Type, target *Type, reportErrors b
41534153
}
41544154
return TernaryFalse
41554155
}
4156-
if target.objectFlags&ObjectFlagsFreshLiteral != 0 {
4156+
if isObjectLiteralType(target) {
41574157
for _, sourceProp := range excludeProperties(r.c.getPropertiesOfType(source), excludedProperties) {
41584158
if r.c.getPropertyOfObjectType(target, sourceProp.Name) == nil {
41594159
if reportErrors {

testdata/baselines/reference/compiler/freshObjectLiteralSubtype.symbols

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function validate() {
2929

3030
if(Math.random() > 0.5) {
3131
>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
32-
>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
32+
>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.esnext.float16.d.ts, --, --))
3333
>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
3434

3535
return utilValidate();
@@ -63,3 +63,67 @@ validate().msg; // Error in TSGO
6363
>validate : Symbol(validate, Decl(freshObjectLiteralSubtype.ts, 9, 8))
6464
>msg : Symbol(msg, Decl(freshObjectLiteralSubtype.ts, 22, 19), Decl(freshObjectLiteralSubtype.ts, 25, 19))
6565

66+
// https://github.com/microsoft/typescript-go/issues/1761
67+
68+
function normalise_trace_logs([log]: any[]) {
69+
>normalise_trace_logs : Symbol(normalise_trace_logs, Decl(freshObjectLiteralSubtype.ts, 29, 15))
70+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 33, 31))
71+
72+
let normalised = [];
73+
>normalised : Symbol(normalised, Decl(freshObjectLiteralSubtype.ts, 34, 4))
74+
75+
if (typeof log === "string" && log.includes("%c")) {
76+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 33, 31))
77+
>log.includes : Symbol(String.includes, Decl(lib.es2015.core.d.ts, --, --))
78+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 33, 31))
79+
>includes : Symbol(String.includes, Decl(lib.es2015.core.d.ts, --, --))
80+
81+
normalised.push({ log, highlighted: log.includes("foo") });
82+
>normalised.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
83+
>normalised : Symbol(normalised, Decl(freshObjectLiteralSubtype.ts, 34, 4))
84+
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
85+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 36, 25))
86+
>highlighted : Symbol(highlighted, Decl(freshObjectLiteralSubtype.ts, 36, 30))
87+
>log.includes : Symbol(String.includes, Decl(lib.es2015.core.d.ts, --, --))
88+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 33, 31))
89+
>includes : Symbol(String.includes, Decl(lib.es2015.core.d.ts, --, --))
90+
91+
} else {
92+
normalised.push({ log });
93+
>normalised.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
94+
>normalised : Symbol(normalised, Decl(freshObjectLiteralSubtype.ts, 34, 4))
95+
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
96+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 38, 25))
97+
}
98+
return normalised;
99+
>normalised : Symbol(normalised, Decl(freshObjectLiteralSubtype.ts, 34, 4))
100+
}
101+
102+
function equal<T>(_actual: T, _expected: T): void {}
103+
>equal : Symbol(equal, Decl(freshObjectLiteralSubtype.ts, 41, 1))
104+
>T : Symbol(T, Decl(freshObjectLiteralSubtype.ts, 43, 15))
105+
>_actual : Symbol(_actual, Decl(freshObjectLiteralSubtype.ts, 43, 18))
106+
>T : Symbol(T, Decl(freshObjectLiteralSubtype.ts, 43, 15))
107+
>_expected : Symbol(_expected, Decl(freshObjectLiteralSubtype.ts, 43, 29))
108+
>T : Symbol(T, Decl(freshObjectLiteralSubtype.ts, 43, 15))
109+
110+
equal(normalise_trace_logs([]), [
111+
>equal : Symbol(equal, Decl(freshObjectLiteralSubtype.ts, 41, 1))
112+
>normalise_trace_logs : Symbol(normalise_trace_logs, Decl(freshObjectLiteralSubtype.ts, 29, 15))
113+
114+
{ log: 'effect' },
115+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 46, 5))
116+
117+
{ log: '$derived', highlighted: true },
118+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 47, 5))
119+
>highlighted : Symbol(highlighted, Decl(freshObjectLiteralSubtype.ts, 47, 22))
120+
121+
{ log: 'double', highlighted: false },
122+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 48, 5))
123+
>highlighted : Symbol(highlighted, Decl(freshObjectLiteralSubtype.ts, 48, 20))
124+
125+
{ log: 4 },
126+
>log : Symbol(log, Decl(freshObjectLiteralSubtype.ts, 49, 5))
127+
128+
]);
129+

testdata/baselines/reference/compiler/freshObjectLiteralSubtype.types

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,91 @@ validate().msg; // Error in TSGO
7878
>validate : () => { valid: boolean; msg?: undefined; } | { valid: boolean; msg: string; }
7979
>msg : string | undefined
8080

81+
// https://github.com/microsoft/typescript-go/issues/1761
82+
83+
function normalise_trace_logs([log]: any[]) {
84+
>normalise_trace_logs : ([log]: any[]) => ({ log: string; highlighted: boolean; } | { highlighted?: undefined; log: any; })[]
85+
>log : any
86+
87+
let normalised = [];
88+
>normalised : any[]
89+
>[] : never[]
90+
91+
if (typeof log === "string" && log.includes("%c")) {
92+
>typeof log === "string" && log.includes("%c") : boolean
93+
>typeof log === "string" : boolean
94+
>typeof log : "bigint" | "boolean" | "function" | "number" | "object" | "string" | "symbol" | "undefined"
95+
>log : any
96+
>"string" : "string"
97+
>log.includes("%c") : boolean
98+
>log.includes : (searchString: string, position?: number | undefined) => boolean
99+
>log : string
100+
>includes : (searchString: string, position?: number | undefined) => boolean
101+
>"%c" : "%c"
102+
103+
normalised.push({ log, highlighted: log.includes("foo") });
104+
>normalised.push({ log, highlighted: log.includes("foo") }) : number
105+
>normalised.push : (...items: any[]) => number
106+
>normalised : any[]
107+
>push : (...items: any[]) => number
108+
>{ log, highlighted: log.includes("foo") } : { log: string; highlighted: boolean; }
109+
>log : string
110+
>highlighted : boolean
111+
>log.includes("foo") : boolean
112+
>log.includes : (searchString: string, position?: number | undefined) => boolean
113+
>log : string
114+
>includes : (searchString: string, position?: number | undefined) => boolean
115+
>"foo" : "foo"
116+
117+
} else {
118+
normalised.push({ log });
119+
>normalised.push({ log }) : number
120+
>normalised.push : (...items: any[]) => number
121+
>normalised : any[]
122+
>push : (...items: any[]) => number
123+
>{ log } : { log: any; }
124+
>log : any
125+
}
126+
return normalised;
127+
>normalised : ({ log: string; highlighted: boolean; } | { log: any; })[]
128+
}
129+
130+
function equal<T>(_actual: T, _expected: T): void {}
131+
>equal : <T>(_actual: T, _expected: T) => void
132+
>_actual : T
133+
>_expected : T
134+
135+
equal(normalise_trace_logs([]), [
136+
>equal(normalise_trace_logs([]), [ { log: 'effect' }, { log: '$derived', highlighted: true }, { log: 'double', highlighted: false }, { log: 4 },]) : void
137+
>equal : <T>(_actual: T, _expected: T) => void
138+
>normalise_trace_logs([]) : ({ log: string; highlighted: boolean; } | { highlighted?: undefined; log: any; })[]
139+
>normalise_trace_logs : ([log]: any[]) => ({ log: string; highlighted: boolean; } | { highlighted?: undefined; log: any; })[]
140+
>[] : never[]
141+
>[ { log: 'effect' }, { log: '$derived', highlighted: true }, { log: 'double', highlighted: false }, { log: 4 },] : ({ log: string; } | { log: string; highlighted: true; } | { log: string; highlighted: false; } | { log: number; })[]
142+
143+
{ log: 'effect' },
144+
>{ log: 'effect' } : { log: string; }
145+
>log : string
146+
>'effect' : "effect"
147+
148+
{ log: '$derived', highlighted: true },
149+
>{ log: '$derived', highlighted: true } : { log: string; highlighted: true; }
150+
>log : string
151+
>'$derived' : "$derived"
152+
>highlighted : true
153+
>true : true
154+
155+
{ log: 'double', highlighted: false },
156+
>{ log: 'double', highlighted: false } : { log: string; highlighted: false; }
157+
>log : string
158+
>'double' : "double"
159+
>highlighted : false
160+
>false : false
161+
162+
{ log: 4 },
163+
>{ log: 4 } : { log: number; }
164+
>log : number
165+
>4 : 4
166+
167+
]);
168+

testdata/tests/cases/compiler/freshObjectLiteralSubtype.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @strict: true
22
// @noEmit: true
3+
// @target: esnext
34

45
function f1() {
56
if (!!true) {
@@ -31,3 +32,24 @@ declare function utilValidate(): {
3132
}
3233

3334
validate().msg; // Error in TSGO
35+
36+
// https://github.com/microsoft/typescript-go/issues/1761
37+
38+
function normalise_trace_logs([log]: any[]) {
39+
let normalised = [];
40+
if (typeof log === "string" && log.includes("%c")) {
41+
normalised.push({ log, highlighted: log.includes("foo") });
42+
} else {
43+
normalised.push({ log });
44+
}
45+
return normalised;
46+
}
47+
48+
function equal<T>(_actual: T, _expected: T): void {}
49+
50+
equal(normalise_trace_logs([]), [
51+
{ log: 'effect' },
52+
{ log: '$derived', highlighted: true },
53+
{ log: 'double', highlighted: false },
54+
{ log: 4 },
55+
]);

0 commit comments

Comments
 (0)