#is declared but its value is never read.

38 messages · Page 1 of 1 (latest)

oak dust
#

Hey so I want to make a simple browser extension and thats my App.tsx:

import { useState } from 'react'
import './App.css'
import * as CryptoJS from 'crypto-js'

function HashString(input: string): string
{
  const hash = CryptoJS.SHA256(input).toString(CryptoJS.enc.Hex);
  return hash;
}

function App() {
  const [count, setCount] = useState(0)

  return (
    <>
      <h1>MessengerEncryptor</h1>
      <div className="card">
        <button onClick={() => setCount((count) => count + 1)}>
          count is {count}
        </button>
      </div>
    </>
  )
}

export default App

for some reason I'm getting error 'HashString' is declared but its value is never read., why is that a problem?

loud drum
#

because it's deadcode, which is probably a mistake. you mightve meant to export that, for example, so you forgetting to do so raises that error

#

it's not an issue in and of itself, but it's a probable result of a mistake

oak dust
#

? i cant just declare a function for later use?

loud drum
#

but you're never using it here.

oak dust
#

yep cuz its not needed yet

#

i will use it later

loud drum
#

then you don't need the function yet

oak dust
#

what?

#

thats kinda stupid

loud drum
#

that's what deadcode means

oak dust
#

i've never seen anything like this in other languages

loud drum
#

or if it's just a generic utility function that may or may not be used in unknown places, then put it in its own module

loud drum
#

ts is acting as a linter in this case

#

tsc errors don't prevent emit/run, though.

oak dust
#

okay

#

so how can i create a new module?

#

i have a template browser extension created with Vite

loud drum
#

just make a new file, put the function in there, and export the function

#

then anything that uses that function just has to import that module

oak dust
#

okey

loud drum
#

your goal of "declare a function for later use" sounds like you don't know where or when it'll be used, so it shouldn't be just in the entry point

oak dust
#

nope thats not it

loud drum
#

but again; if you don't know where or when you're going to use it, you probably just don't need it yet

oak dust
#

i wrote the function

#

and now i wanted to write some frontend stuff

#

that would make use of it

loud drum
#

....okay, so write that?

oak dust
#

i was going to

loud drum
#

just adding this function doesn't do anything useful, that's why linters check for it

oak dust
#

i just wanted to build

#

to see if everything works

loud drum
#

"everything works" kinda doesn't change if the function is there or not since it's not used at all

#

also, IDEs check that for you too

oak dust
loud drum
#

aight this is not a productive convo

oak dust
#

yep