Warning: session_start(): open(/tmp/sess_d8e54df5cf5d1895d17e46bf357120cc, O_RDWR) failed: Disk quota exceeded (122) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: session_start(): Failed to read session data: files (path: /tmp) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_mkdir() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 562

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230
Property Does Not Exist On Type String In Typescript - How To Fix It? - LearnShareIT

Property Does Not Exist On Type String In Typescript – How To Fix It?

Property does not exist on type String in TypeScript

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:

Leave a Reply

Your email address will not be published. Required fields are marked *