1
00:00:00,000 --> 00:00:03,300
Why does a TypeScript private field show up

2
00:00:03,300 --> 00:00:05,600
when I turn this object into text?

3
00:00:05,780 --> 00:00:08,240
TypeScript private stops ordinary

4
00:00:08,240 --> 00:00:10,400
outside access during type checking.

5
00:00:10,400 --> 00:00:13,700
But the private word disappears from the JavaScript.

6
00:00:13,700 --> 00:00:15,100
The field stays.

7
00:00:15,280 --> 00:00:18,380
JavaScript Object Notation, or JSON, is

8
00:00:18,380 --> 00:00:20,200
a text format for data.

9
00:00:20,200 --> 00:00:23,900
Stringify includes ordinary fields like code by default.

10
00:00:23,900 --> 00:00:26,360
That is why code appears in the text.

11
00:00:26,540 --> 00:00:29,420
Does a hash field behave differently?

12
00:00:29,600 --> 00:00:30,280
Yes.

13
00:00:30,280 --> 00:00:34,200
The hash creates a JavaScript private field.

14
00:00:34,200 --> 00:00:36,900
It is not an ordinary property.

15
00:00:36,900 --> 00:00:39,280
With the same stringify call, this

16
00:00:39,280 --> 00:00:41,720
example becomes an empty object.

17
00:00:41,900 --> 00:00:44,080
For a response sent by your

18
00:00:44,080 --> 00:00:47,500
server, explicitly choose what you send.

19
00:00:47,500 --> 00:00:51,700
Neither private form makes secrets safe in browser code.

20
00:00:51,700 --> 00:00:54,940
Code delivered to the browser is available to the user.

21
00:00:55,120 --> 00:00:59,600
My privacy policy was one word.

22
00:00:59,600 --> 00:01:01,800
The compiler deleted it.
