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
Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop
I received some JS code and it won't compile. On closer look it's got some non-standard "commands" peppered through it that remind me of placeholders from web templating, or maybe from compiled JS like TypeScript. I don't know how to tell. What do you all make of this?

code:
    #flock;
    constructor(){
        super();
        this.#flock = new Flock();
        for(var i = 0; i<40; i++){
          let b = new Boid(1,1);
          this.#flock.addBoid(b);
        }

Adbot
ADBOT LOVES YOU

The Fool
Oct 16, 2003


huhu posted:

I just converted my project to Typescript. Almost done playing whack-a-mole but I'm stumped by the following errors:

code:
ERROR in [at-loader] ./node_modules/@types/react-native/globals.d.ts:36:15 
    TS2300: Duplicate identifier 'FormData'.

ERROR in [at-loader] ./node_modules/@types/react-native/globals.d.ts:107:14 
    TS2300: Duplicate identifier 'RequestInfo'.

ERROR in [at-loader] ./node_modules/@types/react-native/globals.d.ts:249:14 
    TS2300: Duplicate identifier 'XMLHttpRequestResponseType'.

ERROR in [at-loader] ./node_modules/@types/react-native/index.d.ts:9561:18 
    TS2717: Subsequent property declarations must have the same type.  Property 'geolocation' must be of type 'Geolocation', but here has type 'GeolocationStatic'.

ERROR in [at-loader] ./node_modules/@types/react-native/index.d.ts:9564:11 
    TS2451: Cannot redeclare block-scoped variable 'navigator'.
A few reasons why I'm confused:
1. My tsconfig.json file contains "exclude": ["node_modules", "build", "scripts"]
2. I'm doing a React project and I'm not really sure where react-native stuff came from.

What should I be Googling because I'm pretty sure I'm searching in the wrong direction.

Just a guess, but could you have installed the types for both regular react and react native, when you only need regular react?

quote:

And a second issue. I've got the following:
code:
class Rate extends Component<any, any> {
    constructor(props) {
        super(props)
        this.state = {
		...
        }
        this.queue = new Queue()
    }
}
What do I do so that Typescript doesn't yell about this.queue.

Declare a type for this.queue somewhere. I like to put it above my constructor.

Something like queue:Queue

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Dumb Lowtax posted:

I received some JS code and it won't compile. On closer look it's got some non-standard "commands" peppered through it that remind me of placeholders from web templating, or maybe from compiled JS like TypeScript. I don't know how to tell. What do you all make of this?

code:
    #flock;
    constructor(){
        super();
        this.#flock = new Flock();
        for(var i = 0; i<40; i++){
          let b = new Boid(1,1);
          this.#flock.addBoid(b);
        }

private class fields https://github.com/tc39/proposal-class-fields#private-fields

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.
More fundamentally misled questions about async and await coming up. Does

JavaScript code:
await arrayOfThingIDs.map( async (thing) => {
  return await db.get(thing);
});

console.log('hi')
block 'hi' until all of the things have been returned from the database? And are the things retrieved from the database in parallel? How about

JavaScript code:
await arrayOfThingIDs.forEach( async (thing) => {
  doSomethingWith(await db.get(thing))
});

console.log('hi')
Do all the things get done before 'hi'?

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Newf posted:

More fundamentally misled questions about async and await coming up. Does

JavaScript code:
await arrayOfThingIDs.map( async (thing) => {
  return await db.get(thing);
});

console.log('hi')
block 'hi' until all of the things have been returned from the database? And are the things retrieved from the database in parallel? How about

That await isn't doing anything, it's just building an array of promises. What you probably want is:

JavaScript code:
const results = await Promise.all(arrayOfThingIDs.map( async (thing) => {
  return await db.get(thing);
}));

console.log('hi')
Promise.all is in parallel yes. And it gives up on whatever is going on as soon as there's an error in any of the things.

Nolgthorn fucked around with this message at 11:05 on May 6, 2019

necrotic
Aug 2, 2005
I owe my brother big time for this!
Async/await is nice syntax for promises. It does nothing else to the language. You can await any promise (as in that all example), but not an array itself as that is not a promise.

The fetch feature is the only core JS feature I'm aware of that itself returns a promise and can work with await without any wrapping.

LifeLynx
Feb 27, 2001

Dang so this is like looking over his shoulder in real-time
Grimey Drawer
code:
<span className="item-name" onClick={() => { ClickHandler() } }>{object.name}</span>

function ClickHandler() {
	this.style.color = 'red'
}
This gives me a "TypeError: Cannot read property 'style' of null" error. What can I put in the ClickHandler function that will tell it "Hey you know the element that was clicked on that triggered this function? Change it to red."?

Also since I'm doing this in React, for some reason putting that anonymous function in the onClick of the span tag makes the whole thing re-render as soon as it loads. I noticed that if I just have a function in there, it will load as soon as the page first renders. Seems odd.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



LifeLynx posted:

code:
<span className="item-name" onClick={() => { ClickHandler() } }>{object.name}</span>

function ClickHandler() {
	this.style.color = 'red'
}
This gives me a "TypeError: Cannot read property 'style' of null" error. What can I put in the ClickHandler function that will tell it "Hey you know the element that was clicked on that triggered this function? Change it to red."?

Also since I'm doing this in React, for some reason putting that anonymous function in the onClick of the span tag makes the whole thing re-render as soon as it loads. I noticed that if I just have a function in there, it will load as soon as the page first renders. Seems odd.

I'm 100% sure I'm doing the type annotations right here but I would explicitly pass in the event to the handler (because I hate having to think about what this is):

code:
<span className="item-name" onClick={(e: Event) => { ClickHandler(e) } }>{object.name}</span>

function ClickHandler(event: Event) {
	event.target.style.color = 'red'
}
Or pass the element - up to you!

go play outside Skyler
Nov 7, 2005


LifeLynx posted:

code:
<span className="item-name" onClick={() => { ClickHandler() } }>{object.name}</span>

function ClickHandler() {
	this.style.color = 'red'
}
This gives me a "TypeError: Cannot read property 'style' of null" error. What can I put in the ClickHandler function that will tell it "Hey you know the element that was clicked on that triggered this function? Change it to red."?

Also since I'm doing this in React, for some reason putting that anonymous function in the onClick of the span tag makes the whole thing re-render as soon as it loads. I noticed that if I just have a function in there, it will load as soon as the page first renders. Seems odd.

Arrow notation functions in JS keep the this context. As such, this will be defined as whatever it was in the render function, which probably isn't what you want.

Directly pass the ClickHandler function (without parentheses) and you'll be fine

code:
<span className="item-name" onClick={ ClickHandler }>{object.name}</span>

function ClickHandler() {
	this.style.color = 'red'
}

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

LifeLynx posted:



Also since I'm doing this in React, for some reason putting that anonymous function in the onClick of the span tag makes the whole thing re-render as soon as it loads. I noticed that if I just have a function in there, it will load as soon as the page first renders. Seems odd.

When you put an anon function inside an event handler, it creates a new function each time, and that causes the re-render. So don't do that if you don't want that to happen.

LifeLynx
Feb 27, 2001

Dang so this is like looking over his shoulder in real-time
Grimey Drawer

Lumpy posted:

When you put an anon function inside an event handler, it creates a new function each time, and that causes the re-render. So don't do that if you don't want that to happen.

Is there a reason for that behavior? Seems strange.

I also don't know why this doesn't work:

code:
<span className="card-name" onClick={ function DoTheThing() { this.style.color = 'red' } }>{cardName.name}</span>
or

code:
<span className="card-name" onClick={ function DoTheThing() { ClickHandler }>{cardName.name}</span>

function ClickHandler() {
this.style.color = 'red'
}
Thanks for answering my dumb questions, this thread has been more helpful than even Stack Overflow. I'm used to "this" automatically knowing what element it's referring to.

necrotic
Aug 2, 2005
I owe my brother big time for this!
It shouldn't by itself cause a re-render, but it does create a new function which can be a performance issue. Same reason you shouldn't create an anonymous function inside of a for loop.

edit: that second one is referring to the click function but not actually invoking it. Even if it was the this inside the function your calling would be window and not the event target. MDN has a good article on this and how it works https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

Not sure why the first wouldn't work but I've never tried using inline-functions like that with react.

necrotic fucked around with this message at 23:04 on May 6, 2019

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

LifeLynx posted:

Is there a reason for that behavior? Seems strange.

I also don't know why this doesn't work:

code:
<span className="card-name" onClick={ function DoTheThing() { this.style.color = 'red' } }>{cardName.name}</span>
or

code:
<span className="card-name" onClick={ function DoTheThing() { ClickHandler }>{cardName.name}</span>

function ClickHandler() {
this.style.color = 'red'
}
Thanks for answering my dumb questions, this thread has been more helpful than even Stack Overflow. I'm used to "this" automatically knowing what element it's referring to.

The reason for the behavior:

JavaScript code:
// inside parent component...
const blah = () => alert('poop');
<button onClick={ blah } />
When React checks to see if a render is needed, it sees that onClick has the same 'blah', so no render needed.

JavaScript code:
// inside parent component...
<button onClick={ () => alert('poop') } />
When React checks to see if a render is needed, is sees that it must create a new anon function, so a re-render is always needed.

And the reason the two onClicks above don't work, assuming they are written that way exactly, is in the first instance you have 'this' binding problems, and in the second, you are simply stating 'ClickHandler', not actually calling it. Plus it will probably have 'this' binding problems as well. Javascript is a fun language.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Lumpy posted:

The reason for the behavior:

JavaScript code:
// inside parent component...
const blah = () => alert('poop');
<button onClick={ blah } />
When React checks to see if a render is needed, it sees that onClick has the same 'blah', so no render needed.

JavaScript code:
// inside parent component...
<button onClick={ () => alert('poop') } />
When React checks to see if a render is needed, is sees that it must create a new anon function, so a re-render is always needed.

Careful with terms, this causes the vDOM to see it as a change (and write it to the real DOM) but does not by itself cause a re-render of the react tree (a trigger of the render function). That requires a prop, state or hook value to change (for a functional component).

If a function definition like that caused a re-render it'd be an infinite loop and literally unusable.

edit: your examples are functionally equivalent if the const definition is in the render function.

necrotic fucked around with this message at 13:31 on May 7, 2019

LifeLynx
Feb 27, 2001

Dang so this is like looking over his shoulder in real-time
Grimey Drawer

Lumpy posted:

The reason for the behavior:

And the reason the two onClicks above don't work, assuming they are written that way exactly, is in the first instance you have 'this' binding problems, and in the second, you are simply stating 'ClickHandler', not actually calling it. Plus it will probably have 'this' binding problems as well. Javascript is a fun language.

Oh okay, I see why React would need to re-render there.

New code, same problems. The funny thing is I've seen what I believe to be this exact solution posted on Stack Overflow... it just doesn't work for me. "TypeError: Cannot read property 'handleClick' of undefined".

code:
import React, {useState} from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import AstButton from './AstButton';
import 'normalize.css';
import * as serviceWorker from './serviceWorker';

function sortByKey(array, key) {
    return array.sort(function(a, b) {
        var x = a[key]; var y = b[key];
        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    });
}

function TheCards() {
    let cardMasterList = require('./scryfall-oracle-cards.json')
    let cardMasterListSorted = sortByKey(cardMasterList, 'name')

    const [cardClicked, setCardClicked] = useState(null)

    console.log(cardMasterList[0].name);
    console.log(cardMasterListSorted)

    function handleClick() {
        setCardClicked("this")
        console.log("cardClicked")
    }

    return (
        <form id="card-master-list">
                {cardMasterListSorted
                    .filter(({legalities}) => legalities.vintage === 'legal')
                    .filter(({rarity}) => rarity === 'common' || 'uncommon')
                    .map(
                    (cardName) => {
                        return (
                            <li key={cardName.id}>
                                <span className="card-name" onClick={ 
                                    this.handleClick()
                                }>{cardName.name}</span>
                            </li>
                        )
                    }
                )
            }
        </form>
        )
}

function MainIndex() {
    return(
        <section>
            <App />
            <TheCards />
            <AstButton label="Go!" />
        </section>
    )
}

ReactDOM.render(<MainIndex />, document.querySelector("#root"))

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: [url]https://bit.ly/CRA-PWA[/url]
serviceWorker.unregister();

necrotic
Aug 2, 2005
I owe my brother big time for this!
The handler function is not defined as a property of an object, remove the this when calling it. And you still are not referring to the clicked card in anyway when calling the handler.

Also load the json outside of the react component, dont do it inside a render function ever.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

necrotic posted:

Careful with terms, this causes the vDOM to see it as a change (and write it to the real DOM) but does not by itself cause a re-render of the react tree (a trigger of the render function). That requires a prop, state or hook value to change (for a functional component).

If a function definition like that caused a re-render it'd be an infinite loop and literally unusable.

edit: your examples are functionally equivalent if the const definition is in the render function.

Good point, and a reminder why I shouldn't post before coffee.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



LifeLynx posted:

Thanks for answering my dumb questions, this thread has been more helpful than even Stack Overflow. I'm used to "this" automatically knowing what element it's referring to.

Remember how I said I don't like to have to constantly think about what this refers to? You're learning why.

necrotic
Aug 2, 2005
I owe my brother big time for this!

necrotic posted:

Not sure why the first wouldn't work but I've never tried using inline-functions like that with react.

Oh, right. A normal function definition doesn't bind this to the parent context's this. So same as the previous examples the this in the handler is referring to the global object (window).

Munkeymon posted:

Remember how I said I don't like to have to constantly think about what this refers to? You're learning why.

Yeah, this. Arrow functions have made it a lot easier to work with at least.

LifeLynx
Feb 27, 2001

Dang so this is like looking over his shoulder in real-time
Grimey Drawer
I ended up doing what I wanted to do by putting handleClick inside the functional component, like this:

code:
function TheCards() {

    const [cardClicked, setCardClicked] = useState(null)

    console.log(cardMasterList[0].name);
    console.log(cardMasterListSorted)

    return (
        <section id="theCards">
        <p id="cardClickedDisplay">{cardClicked}</p>
        <form id="card-master-list">
                {cardMasterListSorted
                    .filter(({legalities}) => legalities.vintage === 'legal')
                    .filter(({rarity}) => rarity === 'common' || 'uncommon')
                    .map(
                    (cardName) => {

                        function handleClick() {
                            console.log("cardClicked")
                            setCardClicked(JSON.stringify(cardName))
                            console.log(cardClicked)
                        }

                        return (
                            <li key={cardName.id}>
                                <span className="card-name" onClick={ 
                                    () => { handleClick() }
                                }>{cardName.name}</span>
                            </li>
                        )
                    }
                )
            }
        </form>
        </section>
        )
}
I wanted it so when a card name is clicked on, it displays the JSON data for that object. The next step is being able to take that JSON data and write it to a database of some kind (and also being able to remove objects if needed). I'm aiming to have a "Magic cards I have for trade" kind of app as a learning experience (and it's definitely been an experience).

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE
What is the current hotness in IDE for javascript? I've been bumbling through on my toy projects with emacs and the chrome console, but I think at some point I may want to upgrade a bit.

Osmosisch
Sep 9, 2007

I shall make everyone look like me! Then when they trick each other, they will say "oh that Coyote, he is the smartest one, he can even trick the great Coyote."



Grimey Drawer

ulmont posted:

What is the current hotness in IDE for javascript? I've been bumbling through on my toy projects with emacs and the chrome console, but I think at some point I may want to upgrade a bit.

Vscode.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Webstorm (or any Jetbrains IDE)

Tanners
Dec 13, 2011

woof

ulmont posted:

What is the current hotness in IDE for javascript? I've been bumbling through on my toy projects with emacs and the chrome console, but I think at some point I may want to upgrade a bit.

If you're working on typescript I've found emacs to be pretty needs suiting, but for plain javascript VSCode is really fantastic.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Tanners posted:

If you're working on typescript I've found emacs to be pretty needs suiting, but for plain javascript VSCode is really fantastic.

VSCode is fantastic for TS as well...as you'd expect.

(i prefer jetbrains IDEs tho)

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
This seems like a good place for this rant, even though it's not directly JS/TS - today I learned that Dart is a stupid language for chumps.

Because it's touted as type-safe, but unlike Typescript literally anything can be null whenever it feels like it. List of strings? More like null or list of null-or-strings! Hope you like handling all possible null cases in all your functions every loving time!

I'd been using it for several weeks at work under the impression that it was like Typescript where a type means what you say, and today a reviewer suggested I might want to include tests for what my function does if my list of objects contains nulls and I like was "wait, what the gently caress, my list can contain nulls?" I thought the reviewer was mistaken, but no, the language really is that poo poo. And I mean it's not "can contain nulls" like you can coerce Typescript into doing, it's just flat out happy to accept ["foo", null, "bar"] as a parameter of type List<String>.

I realize Javascript is happy to mix nulls and things too, but that's 100% dynamic typing, Javascript doesn't claim to be type safe so it's expected. Dart is mostly even more type safe oriented than Typescript, but then it goes and pulls this loving nonsense, what the gently caress. Don't use Dart.

(Even Javascript can do compile-time null-rejection if you use the Closure compiler and ask for non-nullable types!)

roomforthetuna fucked around with this message at 02:19 on May 8, 2019

mystes
May 31, 2006

Dart was originally a dynamically typed language that was supposed to replace JavaScript in browsers, before they cast Raise Undead on it.

Volguus
Mar 3, 2009
I used dart in a flutter project recently and it wasnt that bad. I was just learning flutter and dart so the code i wrote was very much not pretty, but for the most part things worked as expected.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Volguus posted:

I used dart in a flutter project recently and it wasnt that bad. I was just learning flutter and dart so the code i wrote was very much not pretty, but for the most part things worked as expected.
Yeah, I was okay with it, "comparable to Typescript" was my conclusion, until someone suggested I should handle null parameters that I didn't account for. That made me realize it was possible (and easy) to deliver nulls by accident, which adjusts my conclusion to "significantly worse than Typescript".

It's barely better than Javascript at that point, in that as you say "for the most part things work as expected". Allowing surprise nulls is just a loving travesty though for a typed language.

I'm using it for Flutter too, which is quite a hefty paradigm shift from any other UI stuff I've done, gives it a bit of a steep learning curve for doing anything advanced, but I don't mind that. I wouldn't even really mind the null thing if it wasn't just so obnoxious. Unexpected nulls are barely even a thing in C++ for the last 8 years, who would make a new language and let them be a thing? It'd also be okay for small solo projects where I can be confident I won't pass myself null values, but for team things you've gotta handle any edge cases your functions make possible that some jackwagon might do, which means basically every function has to begin with "assert(arg!= null); assert(!listArg.contains(null));" which is stupid as gently caress. (Or you have to make a crapload of use of the "?." and "??" operators, which would be wonderful operators for using on parameters that you've described as null-or-a-type.)

In other newish languages that completely gently caress up handling of nulls: Go (click Run, then compare main() against the output, the rest of the stuff is just there as a sort of vaguely-realistic setup for that lovely behavior.)

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I'm pretty sure all of these "compile to javascript" languages are on their way out as using just javascript seems to be the better option every single time. And as a result, instead, we are seeing the emergence of WebAssembly which will just let you program in whatever language you want.

Please god no more "compile to javascript" ty.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Dart was kind of a mashup of Java and JS, so I'm not sure why you'd expect it to be any better about non-null types than those languages. Rust and Kotlin are the two up-and-coming languages I can think of that even have them, with C# getting them soonish. Hell, maybe Java got them in 9, but I'm not up on new Java features.

Not that I'm defending Dart here - just kinda baffled that anyone is expecting it to be better about null handling than its ancestors.

necrotic
Aug 2, 2005
I owe my brother big time for this!
TypeScript is not going anywhere.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Munkeymon posted:

Dart was kind of a mashup of Java and JS, so I'm not sure why you'd expect it to be any better about non-null types than those languages. Rust and Kotlin are the two up-and-coming languages I can think of that even have them, with C# getting them soonish. Hell, maybe Java got them in 9, but I'm not up on new Java features.

Not that I'm defending Dart here - just kinda baffled that anyone is expecting it to be better about null handling than its ancestors.
Typescript is basically Javascript, and is better about null handling than its ancestor.
Java has an @Nullable annotation (a variety of them even!) so linters can tell you to gently caress off with your possibly-nulls. The fact that so many versions of that exist really should have informed a language-maker that there was a desire for this feature.

I wouldn't have particularly expected Dart to be decent in isolation, I expected it to be decent because a team had chosen to use it, and why would you choose to use a language that's worse than Typescript or C++, in a company where lots of people already know Typescript and C++?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



roomforthetuna posted:

Typescript is basically Javascript, and is better about null handling than its ancestor.
Java has an @Nullable annotation (a variety of them even!) so linters can tell you to gently caress off with your possibly-nulls. The fact that so many versions of that exist really should have informed a language-maker that there was a desire for this feature.

I wouldn't have particularly expected Dart to be decent in isolation, I expected it to be decent because a team had chosen to use it, and why would you choose to use a language that's worse than Typescript or C++, in a company where lots of people already know Typescript and C++?

Dart predates Typescript, dude. Or do you mean for Flutter? In that case, it's either because someone at Google wanted to justify keeping Dart alive or post-hoc justify the original effort behind it to juice their career. Sort of like how IIRC Excel only used VB for scripting because Spolsky led the Excel team and VB was his baby before that.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Munkeymon posted:

Dart predates Typescript, dude. Or do you mean for Flutter? In that case, it's either because someone at Google wanted to justify keeping Dart alive or post-hoc justify the original effort behind it to juice their career. Sort of like how IIRC Excel only used VB for scripting because Spolsky led the Excel team and VB was his baby before that.
Yeah, but you were saying you don't get why would I expect a language to behave better than its ancestors - the answer is because I've seen other languages behave better than their same ancestors, Typescript being an example of that. I wasn't saying I think Dart should have learned from Typescript. (Though with its regeneration as a Flutter thing, actually, yes, Dart should have learned from Typescript.)

And yeah, Dart-Flutter is probably based on some career nonsense as you say. It's frustrating because I really appreciate the goals of Flutter, why would you bind it only to a stupid language nobody wants? (Other than as some sort of career nonsense.)

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



roomforthetuna posted:

Yeah, but you were saying you don't get why would I expect a language to behave better than its ancestors - the answer is because I've seen other languages behave better than their same ancestors, Typescript being an example of that. I wasn't saying I think Dart should have learned from Typescript. (Though with its regeneration as a Flutter thing, actually, yes, Dart should have learned from Typescript.)

Just to be clear, you are talking about TS's ~advanced feature~ --strictNullChecks that was added in 2.0 when you talk about 'better behavior', right?

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Munkeymon posted:

Just to be clear, you are talking about TS's ~advanced feature~ --strictNullChecks that was added in 2.0 when you talk about 'better behavior', right?
I don't know, I didn't set any special options while setting up my Typescript, is that feature a default thing now?
Functions that care whether a thing can be null seem pretty core to the language what with the "!" for asserting that a thing that could be null is not null.

Edit: vvvv yeah apparently strictNullChecks is off by default. Maybe I included some recommended strict config file from somewhere, I certainly didn't set the option individually. So yes I am talking about that 'advanced feature'.

roomforthetuna fucked around with this message at 20:00 on May 8, 2019

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



roomforthetuna posted:

I don't know, I didn't set any special options while setting up my Typescript, is that feature a default thing now?
Functions that care whether a thing can be null seem pretty core to the language what with the "!" for asserting that a thing that could be null is not null.

It sure doesn't appear to be? I've never used it outside that playground thing, though, so maybe it's commonly configured with the strict null check 🤷‍♂️

Munkeymon fucked around with this message at 19:06 on May 8, 2019

Chenghiz
Feb 14, 2007

WHITE WHALE
HOLY GRAIL
Yeah the null checking by default is one of the reasons I ended up using flowtype instead of typescript for most of my work.

Adbot
ADBOT LOVES YOU

tankadillo
Aug 15, 2006

TypeScript always looked attractive to me, but since I was relatively new to Javascript I avoided it just because I was already overwhelmed by the massive ecosystem. However, I’ve been using VS Code’s JS type checking feature and it seems pretty awesome. I just use JSDoc comments to define function parameters and occasionally make a declaration file. Most of the time, it infers all the types correctly anyway. It’s helped me catch a lot of errors. Seems like most of the benefits of TS without actually writing TS.

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