Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
Am I expecting too much when I was hoping that VS Code would notify me about stupid small mistakes, like reassigning a const or using = instead of === inside an if? What's the best way to handle this:

-never do mistakes
-attach eslint to every single script separately
-install eslint globally and deal with that hassle?

Obfuscation fucked around with this message at 13:09 on Aug 10, 2018

Adbot
ADBOT LOVES YOU

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell

smackfu posted:

Use WebStorm?

But it costs money! I really like PyCharm though, so I'll check it out.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell

Thermopyle posted:

I realize this is old, but PyCharm is a superset of webstorm...at lease on the professional version, not sure about community edition.

Community version of PyCharm doesn't do javascript, sadly.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
e: or that, whatever, glhf

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
What's the easiest way to turn an existing React app into an Electron app? I tried electron-forge but it was opinionated in ways that I didn't care for and couldn't quickly figure out how to configure. I also looked at some boilerplate projects but they were all massively overcomplicated for what I actually need.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
I've been using [...Array(x)] as a hacky way to initialize empty arrays but this doesn't work in typescript. Is there a better way?

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell

necrotic posted:

Array(x).fill(undefined)

Dunno if it will actually work with undefined as the arg but I don't see why it wouldn't.

It does work, thanks.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
I had a pretty annoying bug today. Turns out that neither tslint or typescript compiler will warn you about referencing an undeclared variable called "name"... because (obviously?) it shadows window.name. I even had a test that covered the bugged code but since jest environment has a default value for window.name while Chrome doesn't, the code worked in tests and broke in production.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell

TheFluff posted:

I would have expected no-restricted-globals to complain about that. Do you have that enabled?

Looks like it was only implemented last week, I guess it's time to update tslint.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
Yarn still doesn't support npm audit fix, right?

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell

Ytlaya posted:

edit: Hm, I think I found what the issue is for the second and third (IE JS not supporting the ellipsis rest syntax or default parameter values), and I'm guessing the issue with the first is something similar. Is there any reason why IE is like this? Safari also seems to frequently have problems that Firefox/Chrome don't have.

Yeah IE doesn't support arrow functions or the spread operator since those are from ES6 and IE hasn't been updated in forever. Look into Babel for transpiling your code to an older standard.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell

oh no computer posted:

code:
// reducer code
const userReducer = (users = [], action) => {
  if (action.type === 'FETCH_USER') {
    return [...users, action.payload];
  }
  return users;
};

The reducer here is why all of your users are getting added to the store after every request, you need some logic here that merges the new users with the already stored ones based on userId or something. Also throw some console.logs to check that the userId gets passed all the way to the action, because if it's null or something then you will actually get all the users in the response.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell

Combat Pretzel posted:

This Node.JS stuff is weeeeeird.

I'm toying around with React Router and dropping both a <Link to="/"> and an <a href="/"> into the document. Within the HTML code they look exactly the same (both plain <a href="/">), yet clicking the one generated by <Link> navigates immediately whereas the manually written <a> reloads the whole page. How does that even happen?



The one made with Link has an event handler attached to it that captures your click and handles it as an app state change instead.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
I haven’t done React in a while, but I’m guessing that at some point there are duplicate strings in the array which causes the key error and after that the component just shows wrong data

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
You are getting a compile time error because [[]] is a nonsensical type that seems to only accept an empty array inside another array? Define return values for your api call, or use 'any' to bypass the type checking

edit: the thing that returns from the api is probably something like [Record<string, string>, Record<string, string>]. The api turns the data into JSON when it sends the response, and JSON has objects instead of dictionaries.

Obfuscation fucked around with this message at 20:19 on Aug 4, 2022

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
Check the position of the screen after scrolling and compare it to element positions, something like this.

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
Now all you need is a state management system that knows which templates to re-render when your state changes and whoops, you have re-invented react

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
As for that latter example, normally you don't use a class in Typescript just to hold data like that, you are using a javascript object and a typescript interface to add types to the contents of that object. Since TS uses duck typing, you don't need to declare an explicit type for your objects, as long as they fulfill the expected interface they are ok.

Not sure if I'm making sense but here's a code example to show what I mean:
TypeScript code:
interface Foo {
	a: string;
}

const doSomethingWithFoo = (foo: Foo): void => console.log(foo.a);

const someData = { a: 'hello' };
doSomethingWithFoo(someData); // this is totally okay
edit: beaten, but at least I have fancy colors

Obfuscation fucked around with this message at 20:12 on Jun 21, 2023

Adbot
ADBOT LOVES YOU

Obfuscation
Jan 1, 2008
Good luck to you, I know you believe in hell
Does anyone know why Temporal is still not ready?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply