0

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?

1 Answer 1

1

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

"rules": { 
    ...
    "no-use-before-declare": false 
    ...
}
Sign up to request clarification or add additional context in comments.

2 Comments

Well, I want to remove the warning, not just avoid it.
I think this is the only solution I can see for now. Thanks

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.