Skip to content

Commit 02d3dfb

Browse files
committed
Add missing baseline files for jsonImportConstAttribute test
1 parent 968c19c commit 02d3dfb

File tree

2 files changed

+218
-0
lines changed

2 files changed

+218
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//// [tests/cases/compiler/jsonImportConstAttribute.ts] ////
2+
3+
=== /config.json ===
4+
{
5+
"appLocales": ["FR", "BE"],
6+
>"appLocales" : Symbol("appLocales", Decl(config.json, 0, 1))
7+
8+
"enabled": true,
9+
>"enabled" : Symbol("enabled", Decl(config.json, 1, 31))
10+
11+
"count": 42
12+
>"count" : Symbol("count", Decl(config.json, 2, 20))
13+
}
14+
15+
=== /main.ts ===
16+
// Without const attribute - types should be widened
17+
import config from "./config.json" with { type: "json" };
18+
>config : Symbol(config, Decl(main.ts, 1, 6))
19+
20+
// With const attribute - types should preserve literal types
21+
import constConfig from "./config.json" with { type: "json", const: "true" };
22+
>constConfig : Symbol(constConfig, Decl(main.ts, 4, 6))
23+
24+
// Test widened types (without const)
25+
type Locales = typeof config.appLocales; // Should be string[]
26+
>Locales : Symbol(Locales, Decl(main.ts, 4, 77))
27+
>config.appLocales : Symbol("appLocales", Decl(config.json, 0, 1))
28+
>config : Symbol(config, Decl(main.ts, 1, 6))
29+
>appLocales : Symbol("appLocales", Decl(config.json, 0, 1))
30+
31+
type Enabled = typeof config.enabled; // Should be boolean
32+
>Enabled : Symbol(Enabled, Decl(main.ts, 7, 40))
33+
>config.enabled : Symbol("enabled", Decl(config.json, 1, 31))
34+
>config : Symbol(config, Decl(main.ts, 1, 6))
35+
>enabled : Symbol("enabled", Decl(config.json, 1, 31))
36+
37+
type Count = typeof config.count; // Should be number
38+
>Count : Symbol(Count, Decl(main.ts, 8, 37))
39+
>config.count : Symbol("count", Decl(config.json, 2, 20))
40+
>config : Symbol(config, Decl(main.ts, 1, 6))
41+
>count : Symbol("count", Decl(config.json, 2, 20))
42+
43+
// Test literal types (with const)
44+
type ConstLocales = typeof constConfig.appLocales; // Should be readonly ["FR", "BE"]
45+
>ConstLocales : Symbol(ConstLocales, Decl(main.ts, 9, 33))
46+
>constConfig.appLocales : Symbol("appLocales", Decl(config.json, 0, 1))
47+
>constConfig : Symbol(constConfig, Decl(main.ts, 4, 6))
48+
>appLocales : Symbol("appLocales", Decl(config.json, 0, 1))
49+
50+
type ConstEnabled = typeof constConfig.enabled; // Should be true
51+
>ConstEnabled : Symbol(ConstEnabled, Decl(main.ts, 12, 50))
52+
>constConfig.enabled : Symbol("enabled", Decl(config.json, 1, 31))
53+
>constConfig : Symbol(constConfig, Decl(main.ts, 4, 6))
54+
>enabled : Symbol("enabled", Decl(config.json, 1, 31))
55+
56+
type ConstCount = typeof constConfig.count; // Should be 42
57+
>ConstCount : Symbol(ConstCount, Decl(main.ts, 13, 47))
58+
>constConfig.count : Symbol("count", Decl(config.json, 2, 20))
59+
>constConfig : Symbol(constConfig, Decl(main.ts, 4, 6))
60+
>count : Symbol("count", Decl(config.json, 2, 20))
61+
62+
// Verify the types work as expected
63+
const locale: "FR" | "BE" = constConfig.appLocales[0]; // Should work with const
64+
>locale : Symbol(locale, Decl(main.ts, 17, 5))
65+
>constConfig.appLocales : Symbol("appLocales", Decl(config.json, 0, 1))
66+
>constConfig : Symbol(constConfig, Decl(main.ts, 4, 6))
67+
>appLocales : Symbol("appLocales", Decl(config.json, 0, 1))
68+
>0 : Symbol(0)
69+
70+
const enabledTrue: true = constConfig.enabled; // Should work with const
71+
>enabledTrue : Symbol(enabledTrue, Decl(main.ts, 18, 5))
72+
>constConfig.enabled : Symbol("enabled", Decl(config.json, 1, 31))
73+
>constConfig : Symbol(constConfig, Decl(main.ts, 4, 6))
74+
>enabled : Symbol("enabled", Decl(config.json, 1, 31))
75+
76+
// These should error without const (uncomment to verify errors)
77+
// const localeError: "FR" | "BE" = config.appLocales[0]; // Error: string not assignable to "FR" | "BE"
78+
// const enabledError: true = config.enabled; // Error: boolean not assignable to true
79+
80+
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//// [tests/cases/compiler/jsonImportConstAttribute.ts] ////
2+
3+
=== /config.json ===
4+
{
5+
>{ "appLocales": ["FR", "BE"], "enabled": true, "count": 42} : { appLocales: string[]; enabled: boolean; count: number; }
6+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7+
8+
"appLocales": ["FR", "BE"],
9+
>"appLocales" : string[]
10+
> : ^^^^^^^^
11+
>["FR", "BE"] : string[]
12+
> : ^^^^^^^^
13+
>"FR" : "FR"
14+
> : ^^^^
15+
>"BE" : "BE"
16+
> : ^^^^
17+
18+
"enabled": true,
19+
>"enabled" : boolean
20+
> : ^^^^^^^
21+
>true : true
22+
> : ^^^^
23+
24+
"count": 42
25+
>"count" : number
26+
> : ^^^^^^
27+
>42 : 42
28+
> : ^^
29+
}
30+
31+
=== /main.ts ===
32+
// Without const attribute - types should be widened
33+
import config from "./config.json" with { type: "json" };
34+
>config : { appLocales: string[]; enabled: boolean; count: number; }
35+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
>type : error
37+
38+
// With const attribute - types should preserve literal types
39+
import constConfig from "./config.json" with { type: "json", const: "true" };
40+
>constConfig : { readonly appLocales: readonly ["FR", "BE"]; readonly enabled: true; readonly count: 42; }
41+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
>type : error
43+
>const : error
44+
45+
// Test widened types (without const)
46+
type Locales = typeof config.appLocales; // Should be string[]
47+
>Locales : string[]
48+
> : ^^^^^^^^
49+
>config.appLocales : string[]
50+
> : ^^^^^^^^
51+
>config : { appLocales: string[]; enabled: boolean; count: number; }
52+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53+
>appLocales : string[]
54+
> : ^^^^^^^^
55+
56+
type Enabled = typeof config.enabled; // Should be boolean
57+
>Enabled : boolean
58+
> : ^^^^^^^
59+
>config.enabled : boolean
60+
> : ^^^^^^^
61+
>config : { appLocales: string[]; enabled: boolean; count: number; }
62+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63+
>enabled : boolean
64+
> : ^^^^^^^
65+
66+
type Count = typeof config.count; // Should be number
67+
>Count : number
68+
> : ^^^^^^
69+
>config.count : number
70+
> : ^^^^^^
71+
>config : { appLocales: string[]; enabled: boolean; count: number; }
72+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73+
>count : number
74+
> : ^^^^^^
75+
76+
// Test literal types (with const)
77+
type ConstLocales = typeof constConfig.appLocales; // Should be readonly ["FR", "BE"]
78+
>ConstLocales : readonly ["FR", "BE"]
79+
> : ^^^^^^^^^^^^^^^^^^^^^
80+
>constConfig.appLocales : readonly ["FR", "BE"]
81+
> : ^^^^^^^^^^^^^^^^^^^^^
82+
>constConfig : { readonly appLocales: readonly ["FR", "BE"]; readonly enabled: true; readonly count: 42; }
83+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84+
>appLocales : readonly ["FR", "BE"]
85+
> : ^^^^^^^^^^^^^^^^^^^^^
86+
87+
type ConstEnabled = typeof constConfig.enabled; // Should be true
88+
>ConstEnabled : true
89+
> : ^^^^
90+
>constConfig.enabled : true
91+
> : ^^^^
92+
>constConfig : { readonly appLocales: readonly ["FR", "BE"]; readonly enabled: true; readonly count: 42; }
93+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94+
>enabled : true
95+
> : ^^^^
96+
97+
type ConstCount = typeof constConfig.count; // Should be 42
98+
>ConstCount : 42
99+
> : ^^
100+
>constConfig.count : 42
101+
> : ^^
102+
>constConfig : { readonly appLocales: readonly ["FR", "BE"]; readonly enabled: true; readonly count: 42; }
103+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104+
>count : 42
105+
> : ^^
106+
107+
// Verify the types work as expected
108+
const locale: "FR" | "BE" = constConfig.appLocales[0]; // Should work with const
109+
>locale : "FR" | "BE"
110+
> : ^^^^^^^^^^^
111+
>constConfig.appLocales[0] : "FR"
112+
> : ^^^^
113+
>constConfig.appLocales : readonly ["FR", "BE"]
114+
> : ^^^^^^^^^^^^^^^^^^^^^
115+
>constConfig : { readonly appLocales: readonly ["FR", "BE"]; readonly enabled: true; readonly count: 42; }
116+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
117+
>appLocales : readonly ["FR", "BE"]
118+
> : ^^^^^^^^^^^^^^^^^^^^^
119+
>0 : 0
120+
> : ^
121+
122+
const enabledTrue: true = constConfig.enabled; // Should work with const
123+
>enabledTrue : true
124+
> : ^^^^
125+
>true : true
126+
> : ^^^^
127+
>constConfig.enabled : true
128+
> : ^^^^
129+
>constConfig : { readonly appLocales: readonly ["FR", "BE"]; readonly enabled: true; readonly count: 42; }
130+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
131+
>enabled : true
132+
> : ^^^^
133+
134+
// These should error without const (uncomment to verify errors)
135+
// const localeError: "FR" | "BE" = config.appLocales[0]; // Error: string not assignable to "FR" | "BE"
136+
// const enabledError: true = config.enabled; // Error: boolean not assignable to true
137+
138+

0 commit comments

Comments
 (0)