Skip to content

Conversation

salvoravida
Copy link

fix TypeError: Cannot read property 'escapedText' of undefined

@pvasek
Copy link
Collaborator

pvasek commented Jun 17, 2019

Thank you for your PR. Could you also add unit test that should be failing before your fix?

It should be pretty straightforward. In __tests__/data/ folder you can place a file which reproduce your issue Issue<# that you trying to fix>.tsx. In the __tests__/parser.ts there is a section issues where you can place the test itself.

@salvoravida
Copy link
Author

hum, it seems that the problem is with array props access:

export interface IFontType {
    fontFamily?: string;
    fontSize?: string;
    fontStretch?: string;
    fontStyle?: string;
    fontWeight?: string | number;
    letterSpacing?: string;
    lineHeight?: string | number;
    textAlign?: string;

    // eventual other props
    [x: string]: any;
}

export interface Definitions {
    1: IFontType;
}

const definitions = <Definitions> {}

definitions[1] = {
        fontFamily: 'dd',
        fontSize: '20px',
        fontWeight: 'normal',
        fontStyle: 'normal',
        fontStretch: 'normal',
        lineHeight: 1.6,
        letterSpacing: 'normal'
    };

export { definitions  }

in this file i get the error here -> definitions[1]

i can't replicate the issue on tests.

anyway i change my src to

export interface IFontType {
    fontFamily?: string;
    fontSize?: string;
    fontStretch?: string;
    fontStyle?: string;
    fontWeight?: string | number;
    letterSpacing?: string;
    lineHeight?: string | number;
    textAlign?: string;

    // eventual other props
    [x: string]: any;
}

export interface Definitions {
    1: IFontType;
}

const definitions :Definitions = {
 1:  {
        fontFamily: 'dd',
        fontSize: '20px',
        fontWeight: 'normal',
        fontStyle: 'normal',
        fontStretch: 'normal',
        lineHeight: 1.6,
        letterSpacing: 'normal'
    }
}
export { definitions  }

@pvasek
Copy link
Collaborator

pvasek commented Jun 19, 2019

Are you talking about typescript error or about the react-docgen-typescript?

Otherwise in general, I think that if there is no test that proofs that something is wrong it make no sense to change the current code. Of course it can happen that tests are written in a way that use a little bit different path that the "real" code but in that case we should figure it out first what's the difference.

@salvoravida
Copy link
Author

if your parser get an error with a valid JS line
definitions[1] (array prop access)
then your parse has a probelm.

anyway you can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants