Knowing how to solve the error “property does not exist on type string” in Typescript will make you know more clearly about what a string is and also about the object. So how to do it? Let’s go into detail now.
The reason for the error “property does not exist on type String” in Typescript
The error happens when you try to access a property that does not support string. You can see my example below.
Example:
const anString:string = 'I like Typescript'
anString.name // ERROR: Property' name' does not exist on type 'string'
Here the error happens because I try to access the name property in string type.
The solution for this error
Using object type
If you want access to a property, you can create it inside the object type and access it.
Example:
const inforObj = {
name: "Arvid Altenwerth",
age: 26,
date: "1996-02-22",
userName: "lolita04",
};
// Access to the property
const name1: string = inforObj.name;
const age1: number = inforObj.age;
const date1: string = inforObj.date;
console.log(name1, age1, date1);
Output:
[LOG]: "Arvid Altenwerth", 26, "1996-02-22"
Here I create inforObj object with four property name, age, date, and username. Then I can access all that property by calling it.
Create specific type
You can also create a new specific type with all property you want to access.
Example:
type inforDetail = {
name: string;
age: number;
date: string;
userName: string;
};
// Create object implement inforDetail type
const person1: inforDetail = {
name: "Arvid Altenwerth",
age: 26,
date: "1996-02-22",
userName: "lolita04",
};
// Access to the property
const name1: string = person1.name;
const age1: number = person1.age;
const date1: string = person1.date;
console.log(name1, age1, date1);
Output:
[LOG]: "Arvid Altenwerth", 26, "1996-02-22"
Here I created a new type called inforDetail. Then I create a new object that implements the inforDetail type, and I can also access each property with the object type. When creating a new type, you also can mandatory a new object to have all the specified properties. If not, it will get the error.
Example:
type inforDetail = {
name: string,
age: number,
date: string,
userName: string
};
const person1: inforDetail = {
name: "Arvid Altenwerth",
age: 26,
date: "1996-02-22",
};
Error:
Property 'userName' is missing in type '{ name: string; age: number; date: string; }' but required in type 'inforDetail'.
Here I get the error because I implement the inforDetail type but missing the userName property, which does not allow.
Summary
In this article, I have explained how to solve the error “property that does not exist on the string type” in Typescript. You can access that property by using an object, or you can create your new own type. Let’s try these methods to get your desired results!
Maybe you are interested:
- File is not under ‘rootDir’ error in TypeScript
- Property is private and only accessible within class in TypeScript
- Property does not exist on type Object in TypeScript

Hello, guys! I hope that my knowledge in HTML, CSS, JavaScript, TypeScript, NodeJS, ReactJS, MongoDB, Python, MySQL, and npm computer languages may be of use to you. I’m Brent Johnson, a software developer.
Name of the university: HOU
Major: IT
Programming Languages: HTML, CSS, JavaScript, TypeScript, NodeJS, ReactJS, MongoDB, PyThon, MySQL, npm