0

I have a typescript:

export const create= () => {
   export const  Size = 5;

   export const now = () => {
    const bytes = new Uint8Array(this.Size); 
   }
}

The code runs fine in node.js application, but when I try to use it in react-native, I get:

Cannot read property 'Size' of undefined

Obviously when converted to javascript to be used in react-native:

exports.Size = 5;

1 Answer 1

1
  1. You don't need to mark Size and now with export.

  2. Arrow functions don't have a this. They are using the this from the function or class above them. Basically, just use Size instead of this.Size.

Unrelated, but you may want to look at AirBnb styleguide for how to write good code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.