|
Combat Pretzel posted:So in TypeScript, generics are a compile-time thing. Since that's so, why can't I instance generic types? Kinda this sort of stuff. Because the type system is erased at compile time, what would T refer to? There’s no analog here in actual JavaScript so it can’t do anything concrete with T, only referenced as part of the type system. edit: Nolgthorn posted:Confused about what it is. If you want your class to extend another class you should define another class and extend it. Then typescript would surely figure out what you were doing. He wants to go like this: code:
|
# ? Sep 7, 2022 20:18 |
|
|
# ? May 15, 2024 10:09 |
|
Combat Pretzel posted:So in TypeScript, generics are a compile-time thing. Since that's so, why can't I instance generic types? Kinda this sort of stuff. You can create a factory function for <T extends SomeBaseClass> if you want: https://www.typescriptlang.org/docs/handbook/2/generics.html#using-class-types-in-generics You'd still have to get an actual reference for the class you want to instantiate from somewhere though, you can't go off of the type parameter alone. Building off of the example in the link, you could do this for example: TypeScript code:
TheFluff fucked around with this message at 21:15 on Sep 7, 2022 |
# ? Sep 7, 2022 21:04 |
|
Ah thanks fluff. I was pretty sure there was a way but didn’t have the time at the moment to look!
|
# ? Sep 7, 2022 21:08 |
|
I've seen factory function stuff before. I figure it's remnants coming from C# that hinder me from understanding why I can't just put the drat type in the pointy brackets and have the Typescript compiler do its thing in the background.TypeScript code:
Alas, it's not meant to be I guess. Combat Pretzel fucked around with this message at 20:43 on Sep 8, 2022 |
# ? Sep 8, 2022 20:40 |
|
Combat Pretzel posted:I've seen factory function stuff before. I figure it's remnants coming from C# that hinder me from understanding why I can't just put the drat type in the pointy brackets and have the Typescript compiler do its thing in the background. You can't do that because the type in the pointy brackets doesn't exist. Here's what your code actually looks like once TypeScript is done with it: JavaScript code:
|
# ? Sep 8, 2022 23:28 |
|
Yup. TypeScript is not C#, and it becomes JavaScript which is definitely not C#.
|
# ? Sep 9, 2022 00:22 |
|
Nolgthorn posted:I found the solution it is the following: In the end I stripped all of this out. Everything really. Instead, I record where the drag handle opposite to the click position is. Then while dragging, depending on which handle it is I record the difference in start position to be position as either plus or minus height or width. Then, I change the dimensions of the container adjusting it to its aspect ratio based on whether it's too tall or too wide, no need for dot product or outer product. Then, I reposition it so that the opposite drag handle remains in place. It's that easy.
|
# ? Sep 17, 2022 21:12 |
|
I don't use javascript/typescript too often and I'm running into a issue. I have some .ts files that are just basic models. they look something like:code:
code:
code:
|
# ? Sep 19, 2022 18:39 |
|
JS does't support types, so when you compile your TS to JS, it all gets removed. TS is just a tool to help the developer but none of it is actually being run in the browser
|
# ? Sep 19, 2022 18:51 |
|
Does anyone have experience using Zod (https://github.com/colinhacks/zod) in TypeScript projects?
|
# ? Sep 19, 2022 18:57 |
|
teen phone cutie posted:JS does't support types, so when you compile your TS to JS, it all gets removed. TS is just a tool to help the developer but none of it is actually being run in the browser So there is no way to compile the .ts I have into usable .js files?
|
# ? Sep 19, 2022 19:12 |
|
sausage king of Chicago posted:So there is no way to compile the .ts I have into usable .js files? i mean, yeah, your TS should compile to JS and be executable after it's converted - I'm just saying if you have a file that has just a bunch of exported types, it's all gonna get scrubbed at compile time and you'll have a "blank" file.
|
# ? Sep 19, 2022 19:28 |
|
To clarify that further, an interface is a type, not a value. It says something about the shape of a value but isn't a value in itself. Nothing like that exists in Javascript, it's only useful to the Typescript compiler. For example:TypeScript code:
TheFluff fucked around with this message at 20:06 on Sep 19, 2022 |
# ? Sep 19, 2022 20:00 |
|
No Starch keeps kicking out the Javascript crash course book and I realize js changes quick and a lot so thats expected but I do enjoy books/similarly well structured mediums. What is a good js book for someone that has a good backend understanding but hasn't been able to get into front end (I tried to do django but got lost). I tried eloquent Javascript but the author felt like he was missing the forest for the trees and treating js like python/java/etc in lieu of a means for making websites. jiffypop45 fucked around with this message at 21:04 on Sep 19, 2022 |
# ? Sep 19, 2022 20:55 |
|
TheFluff posted:To clarify that further, an interface is a type, not a value. It says something about the shape of a value but isn't a value in itself. Nothing like that exists in Javascript, it's only useful to the Typescript compiler. For example: I'm trying to get that to compile into a package so it can be imported and used in other projects. I expected the files generated would have the properties listed, but it has nothing. I didn't know if there was something wrong with my .tsconfig, but I guess I just can't do what I was trying to do...?
|
# ? Sep 21, 2022 15:22 |
|
sausage king of Chicago posted:I'm trying to get that to compile into a package so it can be imported and used in other projects. I expected the files generated would have the properties listed, but it has nothing. I didn't know if there was something wrong with my .tsconfig, but I guess I just can't do what I was trying to do...? If you want a type to show up in a type definition file so it can used by other libraries, it needs to be declared an export type.
|
# ? Sep 21, 2022 15:53 |
|
I am hitting a roadblock on a seemingly simple thing to do, but apparently it's not so simple. I have a json list and I am trying to find the value (amount) of the item immediately less than or equal to a given value and also the next highest value. code:
I am sure this is much easier than I think but I can't see the forest for all the trees. Any help is greatly appreciated.
|
# ? Sep 21, 2022 15:58 |
|
Sort list by value, filter out anything with value < target, pick the top 2 items off the sorted list? Or were you looking for an actual code snippet.
|
# ? Sep 21, 2022 16:01 |
|
sausage king of Chicago posted:I'm trying to get that to compile into a package so it can be imported and used in other projects. I expected the files generated would have the properties listed, but it has nothing. I didn't know if there was something wrong with my .tsconfig, but I guess I just can't do what I was trying to do...? You don’t actually have to do anything to your code make a package, if it has a package.json, it’s a package. Just make sure the entry points are set up how you want it. You only need to compile it so it can be used as JavaScript, not typescript.
|
# ? Sep 21, 2022 16:09 |
|
minato posted:Sort list by value, filter out anything with value < target, pick the top 2 items off the sorted list? Or were you looking for an actual code snippet. About 2 minutes after I wrote my post I figured this out, it was right in front of my eyes the whole time. code:
|
# ? Sep 21, 2022 16:11 |
|
sausage king of Chicago posted:I'm trying to get that to compile into a package so it can be imported and used in other projects. I expected the files generated would have the properties listed, but it has nothing. I didn't know if there was something wrong with my .tsconfig, but I guess I just can't do what I was trying to do...? if it's the types you want to expose for importing, it looks like you might be doing that already judging by your tsconfig. are you generating d.ts files? that's the file through which the user would go about importing the types and interfaces e: to further clarify, you have "declaration: true" in your tsconfig, meaning that the TypeScript compiler is both turning your TS code into JavaScript, but also creating d.ts files which are responsible for mapping the JS to the TS interfaces and types when the user imports your JS in their TS files. Alternatively, if you have a tool like Babel transpiling code as well, it might be useful having the typescript compiler only emit d.ts files with the "emitDeclarationOnly" flag and have Babel take care of the transpilation. Could you tell us more about your build process? and also what your package.json look like? teen phone cutie fucked around with this message at 16:41 on Sep 21, 2022 |
# ? Sep 21, 2022 16:12 |
|
ModeSix posted:About 2 minutes after I wrote my post I figured this out, it was right in front of my eyes the whole time. misread the assignment. I'd use `Array.reduce()` and return an object or a tuple providing immediate lesser and immediate greater values, as it can do it in one pass. Your suggestion is not robust as it doesn't deal with empty arrays, or arrays with only one value, or arrays that can contain only greater or only lesser amounts... gbut fucked around with this message at 16:23 on Sep 21, 2022 |
# ? Sep 21, 2022 16:16 |
|
Help appreciated from all on this. Your suggestions pushed me in the right direction and I am sorting the array prior to searching then capturing the index of the item immediately higher than the value and moving downwards in the array index after that. Thanks!
|
# ? Sep 21, 2022 16:35 |
|
I think this is a really easy question but anything to do with asynchronous programming and callbacks etc. still fries my brain to an embarrassing degree. I want to crawl five pages of a website using the node "crawler" package. The url for page 2 comes from the content of page 1, and so on for pages 3-5, so I need to wait until I have the content of the preceding page before queuing up a crawl of the next page. Really simplified version of the basic crawler: JavaScript code:
JavaScript code:
edit: I did it with a promise: JavaScript code:
fuf fucked around with this message at 13:34 on Sep 25, 2022 |
# ? Sep 25, 2022 13:04 |
|
Not sure if this is the correct thread, but my work wants me to learn Javascript to work with some automation software, and I have always wanted to learn it. But I haven't done any programming since high school. Is there a recommended online resource for learning Javascript?
|
# ? Sep 27, 2022 03:17 |
Peachfart posted:Not sure if this is the correct thread, but my work wants me to learn Javascript to work with some automation software, and I have always wanted to learn it. But I haven't done any programming since high school. Is there a recommended online resource for learning Javascript? Modern Javascript is pretty good. That said, I would heartily recommend using Typescript from the get-go if at all possible, since its typing lets you avoid a lot of really irritating pitfalls caused by Javascript's loose typing and enables automated refactoring.
|
|
# ? Sep 27, 2022 15:05 |
|
Osmosisch posted:Modern Javascript is pretty good. Seconding this, TS is superior to JS, and is its superset. Meaning: JS _should_ be valid TS, but not other way around. Of course, there are details that don't really work that way sometimes, but the spirit is there. Unless your API for automation requires vanilla JS. In that case you might be stuck with a specific JS version, or be forced to use some transpiler to get the output you're feeding to the system be the correct JS version. In the latter case, it should be (relatively) trivial to set up a pipeline that allows you to use TS or modern JS with your automation system. But setting this pipeline requires prior knowledge of JS to some degree.
|
# ? Sep 27, 2022 15:19 |
|
Peachfart posted:Not sure if this is the correct thread, but my work wants me to learn Javascript to work with some automation software, and I have always wanted to learn it. But I haven't done any programming since high school. Is there a recommended online resource for learning Javascript? learn more about the api and get code samples of using the automation interface before looking at books or asking questions. it's easily possible that by "automation api", your workplace means some horrible windows activex poo poo that many of the other people in the thread are too young to have experienced. most people posting here are going to be coming from a "js in browser" or "nodejs" context, and that will hurt you if the actual environment is "we're somehow still using cscript in 2022."
|
# ? Sep 27, 2022 16:30 |
|
Osmosisch posted:Modern Javascript is pretty good. And use Jest instead of Mocha
|
# ? Sep 27, 2022 18:54 |
|
https://www.npmjs.com/package/kequapp Recently updated my Node app framework and am interested in feedback if you like it. <3
|
# ? Oct 2, 2022 17:43 |
|
fuf posted:edit: I did it with a promise: I suggest you take a look at async/await, it's much more readable than callbacks and promises.
|
# ? Oct 3, 2022 20:23 |
|
I have a function:code:
code:
edit: I figured it out; you just break in javascript switch cases unlike PHP ones where you return then break worms butthole guy fucked around with this message at 22:14 on Oct 3, 2022 |
# ? Oct 3, 2022 22:08 |
|
I'm trying to learn typescript better and this error is confusing me. Code:code:
code:
|
# ? Oct 19, 2022 02:38 |
|
If your property on the interface can only be read from, you just specify it as readonly postParent; An implementation of the interface can fulfil that by using a getter, if that's what it wants to do. But that's an implementation detail, all that the interface specifies is that it has a property called postParent that you are allowed to read from.
|
# ? Oct 19, 2022 02:53 |
|
That is a loving terrible error message given how likely this mistake is though. Well worth a "was the string get? Append 'did you mean readonly'" sort of treatment
|
# ? Oct 19, 2022 03:20 |
|
Osmosisch posted:Modern Javascript is pretty good. Disagree about the Typescript from the get go. I'm not sure the benefits of TS really outweigh its added complexity unless until someone already has a pretty good handle on JavaScript. Plus, if they're learning JS in order to interact with already existing automation software, they're probably not going to be able to put much of that TS knowledge to use anyway.
|
# ? Oct 19, 2022 03:36 |
|
Thanks and yeah that error sucks. I've been playing around with ts pondering the idea of using it as an alternative to lua for making a thoroughly mod friendly game. Despite the goofy error I certainly enjoy writing ts a hell of a lot more than lua.
|
# ? Oct 19, 2022 04:11 |
|
fsif posted:Disagree about the Typescript from the get go. I'm not sure the benefits of TS really outweigh its added complexity unless until someone already has a pretty good handle on JavaScript. Plus, if they're learning JS in order to interact with already existing automation software, they're probably not going to be able to put much of that TS knowledge to use anyway. After I got used to Typescript I just love it too much. Makes writing code so easy, I know what everything is and it always forces me to deal with every possible eventuality.
|
# ? Oct 19, 2022 19:18 |
|
Nolgthorn posted:After I got used to Typescript I just love it too much. Makes writing code so easy, I know what everything is and it always forces me to deal with every possible eventuality. I probably would've discarded typescript as being dumb bullshit if I didn't write javascript for a few years before learning typescript.
|
# ? Oct 19, 2022 19:56 |
|
|
# ? May 15, 2024 10:09 |
|
That wasn't intended as an anti-TypeScript comment (though I do think it's overprescribed by its evangelists) but more a suggestion for someone new to JavaScript. It's hard enough to learn JS; piling on a bunch of TS tooling and type errors and conventions right at the onset of learning, especially to interact with a non-TypeScript tool, feels unnecessarily arduous.
|
# ? Oct 19, 2022 20:13 |