S
S
Sergey Zolotarev2021-09-06 07:05:20
typescript
Sergey Zolotarev, 2021-09-06 07:05:20

Is it possible to apply an array key in a class method?

Good morning!
Today I encountered a small bug, which I brought to the end of the implementation of an OOP solution in TypeScript for a mobile application with the Expo SDK, and the compiler brought bad news:
TypeError: Cannot read property 'feedTitle' of undefined
And the error itself referred to an excerpt from a whole example code:

import * as React from 'react';
import { Text, View } from 'react-native';
import { StoresFeed } from '../handlers/stores/homepage/Feed';

export function Stores(){
    return (
        <React.Fragment>
            <Text style={pageStyle.feedTitle}>Ближайшие магазины</Text>
            <Text style={pageStyle.feedTitle}>Лучшие товары</Text>
            <Text style={pageStyle.listTitle}>Лучшие категории</Text>
            <Text style={pageStyle.feedTitle}>Выгодные цены</Text>
            <Text style={pageStyle.listTitle}>Категории</Text>
        </React.Fragment>
    );
}

const pageStyle = new StoresFeed('ui-change',0).eventStart();

The class itself with the method consists of StyleSheet style keys, which should work and how to solve this issue correctly (the code itself with the class and not only in the comments to this question)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexandroppolus, 2021-09-06
@seregazolotaryow64

eventStart method returns nothing

D
Dmitry Belyaev, 2021-09-06
@bingo347

Enable strictNullChecks to catch such errors at compile time
PS

storesFeed: any;
constructor(event: any,type: any){
what is the point in TypeScript if you write any everywhere?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question