Siraj Alam
Siraj Alam

Reputation: 10055

Defining variable after declaration throwing error not defined

I wanted to use a variable before its definition,

interface IProps extends WithStyles<typeof STYLES>;

const STYLES = () => ({ })

it was not causing any error, but a warning

STYLES used before defined no-use-before-define

So I read somewhere and declare it before using, like following-

declare let STYLES: () => ({})

interface IProps extends WithStyles<typeof STYLES>;

STYLES = () => ({})

Now the console is clear, no warnings and no error, but at run time I am getting an error that

ReferenceError: STYLES is not defined.

I have tried by making STYLES variable while defining, like

let STYLES = () => ({})

but it causing the error

Cannot redeclare block-scoped variable 'STYLES'.

So the question is, How can I define the variable before it's used without getting any warning and errors?

Upvotes: 0

Views: 82

Answers (1)

RobrechtVM
RobrechtVM

Reputation: 936

Edit your tslint.json file and edit the rules part so that it looks like this

"rules": { 
    ...
    "no-use-before-declare": false 
    ...
}

Upvotes: 1

Related Questions