How to Fix TypeScript TS2339 “Property does not exist on type” Error
The TypeScript error error TS2339: Property 'email' does not exist on type 'User'. appears when you read or write a property that is not declared in the object's type. The fix depends on the type shown in the error. You can add the property to the type, write the type when you declare the variable, or narrow a union type with if. Any of these makes the error go away.
This error shows up when you read values from user data or a response object received from an API, or from a settings object that gets new properties added over time. In my test environment, I triggered this error in three ways. I checked the full message with both tsc and the language server that editors use, and confirmed that the error disappears after each fix.
The test environment was Ubuntu 24.04, Node.js 22.23.4, and TypeScript 7.0.2. I used a tsconfig.json created by npx tsc --init (it includes "strict": true) without changes. For the errors shown in the editor, I ran the TypeScript 7 language server (tsc --lsp --stdio) directly, not the editor itself such as VS Code. I did not test how the error looks in VS Code's UI, versions of TypeScript before 7, or cases where the error appears inside frameworks such as React.
The full error and how to read it
In src/user.ts, I created a User type with only id and name, then wrote a function that reads email, which is not in the type.
type User = {
id: number;
name: string;
};
export function contactLabel(user: User): string {
return `${user.name} <${user.email}>`;
}
console.log(contactLabel({ id: 1, name: "たま" }));
Running npx tsc --noEmit produced the following output (exit code 1).
src/user.ts(7,32): error TS2339: Property 'email' does not exist on type 'User'.
(7,32) is line 7, column 32, which is the position of email in user.email. The message means that the User type has no property named email. The text after on type shows the type that TypeScript sees for that variable. When you look for the place to fix, check this type first.
Adding --pretty shows the location with a squiggly underline (I removed the control characters used for color).
src/user.ts:7:32 - error TS2339: Property 'email' does not exist on type 'User'.
7 return `${user.name} <${user.email}>`;
~~~~~
Found 1 error in src/user.ts:7
The same message appears in the language server
I started the TypeScript 7.0.2 language server with tsc --lsp --stdio and sent it the LSP notification that opens src/user.ts, as an editor does. I also asked for the type information (hover) at the position of email. The returned diagnostics and hover results are shown below. I printed the returned JSON with a small script I wrote.
server: typescript-go 7.0.2
diagnostics (1):
7:32-7:37 severity=1 source=ts code=2339 Property 'email' does not exist on type 'User'.
hover 7:33: any
severity=1 is the value that the LSP specification uses for errors. The message text was the same as in tsc. Because the property does not exist in the type, the type of user.email shown by hover was any.
JavaScript is still emitted despite the error
tsc writes JavaScript even when there are errors. As described in the tsconfig reference for noEmitOnError (English), the default for not emitting on error is false.
When I emitted with --outDir dist despite the error, tsc exited with code 2 and created dist/user.js. Running it with Node.js raised no error and printed the following.
たま <undefined>
As described in the TypeScript Handbook (English), in JavaScript, reading a property that does not exist gives undefined, not a runtime error. TS2339 stops this undefined from reaching the screen.
Add the property to the type
If some users have email and others do not, add email to the User type. Adding ? after the name makes the property optional (see the Handbook's section on Optional Properties (English)).
type User = {
id: number;
name: string;
email?: string;
};
export function contactLabel(user: User): string {
return `${user.name} <${user.email ?? "未登録"}>`;
}
console.log(contactLabel({ id: 1, name: "たま" }));
console.log(contactLabel({ id: 2, name: "みけ", email: "mike@example.com" }));
npx tsc --noEmit printed nothing and exited with code 0, and the language server returned 0 diagnostics. The type of user.email shown by hover was (property) email?: string | undefined. An optional property can be undefined, so I used ?? to show a fallback string (the Japanese text for "not registered") when the value is missing. The output after emitting and running was as follows.
たま <未登録>
みけ <mike@example.com>
When the property name has the wrong capitalization, the error is TS2551, not TS2339, and TypeScript suggests the correct name. This happens when User has name and the code writes return user.Name;.
src/typo.ts(7,15): error TS2551: Property 'Name' does not exist on type 'User'. Did you mean 'name'?
For objects that get properties later, write the type first
If you create a variable without a type, such as const settings = { theme: "dark" }, its type is determined from the value you first assign (see the Handbook's section on type inference for variables (English)). So if you add another property later, you get TS2339.
const settings = { theme: "dark" };
settings.fontSize = 14;
const config = {};
config.port = 3000;
export { settings, config };
src/settings.ts(2,10): error TS2339: Property 'fontSize' does not exist on type '{ theme: string; }'.
src/settings.ts(5,8): error TS2339: Property 'port' does not exist on type '{}'.
After on type, the message shows the contents of the type, such as { theme: string; } or {}, instead of a type name. In the language server hover, the type of settings was { theme: string; } and the type of config was {}. A variable that starts from an empty object {} gets a type with no properties at all.
If you will add properties later, define a type with those properties marked ? and annotate the variable with it.
type Settings = {
theme: string;
fontSize?: number;
};
const settings: Settings = { theme: "dark" };
settings.fontSize = 14;
type Config = {
port?: number;
};
const config: Config = {};
config.port = 3000;
export { settings, config };
After this change, npx tsc --noEmit exited with code 0.
For a property that exists in only one member of a union, narrow with if
A response whose shape differs between success and failure is sometimes written as a union type (types joined with |). When I read data, which exists only in the success case, directly from a variable of this type, I got TS2339.
type Result =
| { ok: true; data: string }
| { ok: false; error: string };
export function show(result: Result): string {
return result.data;
}
src/result.ts(6,17): error TS2339: Property 'data' does not exist on type 'Result'.
Property 'data' does not exist on type '{ ok: false; error: string; }'.
In this case, the message has two lines. The first line is about the whole Result type. The second line shows which member of the union lacks data. Here it is the failure member, { ok: false; error: string; }. The Handbook's section on union types (English) says that for a value of a union type, you can only use operations that work for every member of the union. Instead of adding data to Result, I rewrote the code to read data only in the success case.
export function show(result: Result): string {
if (result.ok) {
return result.data;
}
return `失敗: ${result.error}`;
}
console.log(show({ ok: true, data: "保存しました" }));
console.log(show({ ok: false, error: "通信できません" }));
npx tsc --noEmit exited with code 0. Hovering over result inside if (result.ok) showed that its type was narrowed to { ok: true; data: string; } only. When every member of a union has a property whose value is fixed to a literal such as true or false, and you branch on that property, TypeScript narrows the type. The Handbook's Narrowing chapter (English) calls this kind of union a discriminated union. After emitting and running, the output was as follows.
保存しました
失敗: 通信できません
For a union with no shared property like ok, you can narrow with the in operator (see the in operator section of the Narrowing chapter (English)). I rewrote if (result.ok) as if ("data" in result), and tsc reported no errors for that file.
If the second line of the message shows one member of a union, narrow the type with if. If the text after on type is something like { theme: string; } or {}, annotate the variable with a type. For any other type name that you defined yourself, add the property to that type.





