#tsserver validator false positive report

1 messages ยท Page 1 of 1 (latest)

tawny ventureBOT
#
sequencerr#0

Preview:ts const obj = {page: 1, perPage: 20} function getPageParamsFromExecutionContext() { let page, perPage switch (Math.random() > 0.5 ? "http" : "ws") { case "http": return ({page, perPage} = obj) case "ws": return ({page, perPage} = obj ...

vapid kelp
#

known issue?

vapid kelp
#

!helper

alpine osprey
#

they are unused, assignment evaluates to the rhs operand.

#

so you're basically just returning obj directly there

vapid kelp
#

this code*

alpine osprey
#

variables that are only assigned to, but not read from, are considered unused

#

the code will absolutely work without them

#

your code behaves the same as if it were this

tawny ventureBOT
#
that_guy977#0

Preview:ts const obj = {page: 1, perPage: 20} function getPageParamsFromExecutionContext() { switch (Math.random() > 0.5 ? "http" : "ws") { case "http": return obj case "ws": return obj default: throw new Error("Unsupported protocol") ...

alpine osprey
#

a "used" variable is one that is read

inner talon
#

The code you have there basically boils down to this. As said before, the RHS is what gets returned

const { page, perPage } = obj;
return obj;
vapid kelp
vapid kelp
tawny ventureBOT
#
sequencerr#0

Preview:ts const obj = {page: 1, perPage: 20} function getPageParamsFromExecutionContext() { // let page, perPage; switch (Math.random() > 0.5 ? "http" : "ws") { case "http": return ({page, perPage} = obj) case "ws": return ({page, perPage} = obj ...

vapid kelp
#

you should have tried this guys

#

!helper

inner talon
#

You're using the destructuring syntax to do the assignment

vapid kelp
#

so?

inner talon
#

So you assign values to page and perPage and then you're never using them

#

Which is why it's telling you they are unused

#

Because you don't use page or perPage, you just assign them

vapid kelp
#

what a god damn helpful report. shouldn't it be removed?

#

just a no sense

inner talon
#

No, it's telling you that the variables are being assigned in a local function and not used

vapid kelp
#

they are returned, why should I care

inner talon
#
function go() {
  const x = 1; // Unused, in exactly the same way
  return 2;
}
vapid kelp
#

no, return x

inner talon
#

๐Ÿคท

vapid kelp
#

Because you don't use page or perPage, you just assign them

#

let x; return (x = 1)

#

man, I don't think you know what are talking about sometimes

inner talon
#

What warning do you get when you use that code?

#

"x is declared but the value is never read"

vapid kelp
#

cool, what the whole point? as I mentioned, usless report

#

can we open an Issue?

inner talon
#

Yeah, I'll do it for you now

vapid kelp
#

If you are being ironic, I'll do.

#

are you?

inner talon
#

Don't bother, you're just wasting time, they will close it and give the same explanation

vapid kelp
#

๐Ÿ˜€ ๐Ÿ‘

#

<@&608770230818308165> is that what Evan said?

high apex
#

???

halcyon stratus
#

From reading the scrollback this hasn't been a very kind interaction

vapid kelp
#

is it deprecated?

halcyon stratus
#

typescript doesn't really do that

vapid kelp
#

do what

halcyon stratus
#

"deprecate" things

#

backwards compatibility, esp of build tooling has been an important goal for the developers

vapid kelp
#

then people should know some other way if it is as outdated?

#

why would you suggest me to disable it then

brittle wagon
#

It's not outdated, it's just not what most people use.

halcyon stratus
#

it's not outdated. It's like a car from the 1970's it's still perfectly useful, just lacking some of the more modern niceties that we've come to expect

#

use eslint instead, it'll give you way more control

brittle wagon
#

And TS doesn't have eslint-level configurability because it's not really a linter: you can't just stick a // eslint-disable-next-line to hide errors you don't agree with.

vapid kelp
#

How would I know that if you were not told me?)

brittle wagon
#

Are you meaning to come across as hostile?

halcyon stratus
#

you'd ask here or on SO. You don't need to be so combative about it

vapid kelp
brittle wagon
#

Yes, you're coming across as hostile, which is why I'm mentioning it.

halcyon stratus
#

evan was picking up on that too, which is why your interaction ended with them the way it did

vapid kelp
#

I don't intend to be hostile, I don't know guys, English is not my primary language

#

I'm sorry, if so

halcyon stratus
#

it comes across as dismissive

vapid kelp
#

I'm not blaming him for typescript have a usless report, I just state it)

brittle wagon
#

Okay, well, to the original point; no, I would not file a ticket for this.

vapid kelp
#

pardon, do what?

brittle wagon
#

I would change your code.

#

I would not file a ticket/issue/bug report over this.

vapid kelp
#

I did not ask you???

#

evan:

they will close it and give the same explanation
me:
would it be the way he said?

halcyon stratus
brittle wagon
#

Yes, I'm saying if you file a ticket, it'll lkely be closed.

vapid kelp
#

I got it when you said that ts linter is legacy, but people still might use it

brittle wagon
#

That isn't the issue.

#

I think this is just a pretty odd and uncommon pattern and it's unlikely that they are going to want to put extra logic into the compiler to handle this specific pattern.

#

It's pretty easy to change the code to avoid the issue here:

return ({ page: obj.page, perPage: obj.perPage });
#

Or really even just return obj has essentially the same effect.

vapid kelp
#

And I just wanted to say I'm okay with solution, but how would I know if you were not told be that linter is legacy. If you not deprecating things, you might tell people different way

brittle wagon
#

It's not because "the linter is legacy".

vapid kelp
vapid kelp
vapid kelp
brittle wagon
#

I think this is just a pretty odd and uncommon pattern and it's unlikely that they are going to want to put extra logic into the compiler to handle this specific pattern.

#

๐Ÿ‘† This is my reason.

vapid kelp
#

I see webstandrts programmers point. What a joke for programming world, syntax is allowed, but if it's uncommon, we would not either ban nor fix with handling it proper way xD
I just claim my point.

brittle wagon
#

@vapid kelp Are you 100% sure you are not trying to be hostile?

#

I am sorry that you do not like the answer you have been given.

vapid kelp
#

Not to you, just claiming my point about the would. Am I wrong in my point?

halcyon stratus
#

I really don't understand why you don't just disable the option? It doesn't work for you, so disable it

#

only use programming tools that you feel empower you

vapid kelp
#

I switched topic

alpine osprey
#

the rest of the messages didn't load, thanks discord ๐Ÿ™ƒ

vapid kelp
#

wait, "webstandart" said, your nickname is confusing, I though Retsam saying that's what "webstandarts" claiming

halcyon stratus
#

that's the first complaint I've heard. You see it rendered differently?

brittle wagon
#

Also, yes, @alpine osprey is correct, and the linter is correct here.

#

You can run it yourself:

function foo(obj) {
    let x, y;
    return { x, y } = obj;
}
foo({x: 0, y: 0, z: 0 })

this is exactly the same as:

function foo(obj) {
    return obj;
}
foo({x: 0, y: 0, z: 0 })
vapid kelp
alpine osprey
#

i really should've linked the docs page that says this, sorry

brittle wagon
vapid kelp
#

#1178462113186979970 message #1178462113186979970 message these are

#

I thought we finished that topic

alpine osprey
#

the rhs is used for the value, not the lhs

halcyon stratus
brittle wagon
#

If you do not think it is equivalent, give a specific example of how it is different. Because you can run both your version and webstrand's version and they both return the same thing.

alpine osprey
#

if you want to just return page and perPage out of the object, you would destructure then create a new object; destructuring doesn't create a new object in itself

const { page, perPage } = obj;
return { page, perPage };
// return { page: page, perPage: perPage };
``` they are not interchangable because the latter syntax is object property shorthand
vapid kelp
halcyon stratus
#
return ({ page, perPage } = ctxParam.switchToHttp().getRequest());

is strictly equivalent to returning

return ctxParam.switchToHttp().getRequest();

to be clear

vapid kelp
#

As I said, I'm sorry

#

That's clear for me now, thank you

#

!resolved

#

@halcyon stratus don't be mad at me for misreading your nickname)