|
A type assertion. So you are asserting that doAThing returns an object with two keys, foo and bar, which are strings. Don't use with jsx files. e: Oh I guess it's for generics barkbell fucked around with this message at 21:15 on Oct 20, 2020 |
# ? Oct 20, 2020 21:06 |
|
|
# ? Jun 3, 2024 21:55 |
|
necrotic posted:I think that's a generic function and you're providing a type it needs at call time. Forgive me, but what in this context is a generic function. I am a bit confused. edit: I did try googling this but only get results for arrow expressions which is obviously not what I am looking for.
|
# ? Oct 20, 2020 21:39 |
|
Skyarb posted:Forgive me, but what in this context is a generic function. I am a bit confused. generic interfaces look like this code:
so yeah the sample code you posted it a function that either takes that object or returns it, but you’d have to look at the source for that. teen phone cutie fucked around with this message at 22:28 on Oct 20, 2020 |
# ? Oct 20, 2020 22:25 |
|
A simple example:JavaScript code:
|
# ? Oct 20, 2020 23:01 |
Somebody wanted inline table editing in our Confluence instance for work so they added a plugin for it. It drives me nuts though, so I'm trying to write a userscript to disable it on all pages. Currently the only way we can disable it with a built in mechanism is on a per-page basis. It seems like Jira takes all these plugins and combines them into a batch.js file. It's basically got a setTimeout in there looking for tables so it can apply the inline editing on top of them I'm trying to come up with an easy way to short circuit this thing in a userscript so it doesn't work anymore but I couldn't think of a simple way to do it. Any suggestions?
|
|
# ? Oct 20, 2020 23:50 |
|
Cool thanks guys. Kinda weird but good to know, I still often feel lost in typescript.
|
# ? Oct 21, 2020 00:32 |
|
Skyarb posted:I am back to writing typescript after a long while of NOT doing that. Look up generics.
|
# ? Oct 21, 2020 00:51 |
|
Are there any JS packages out there that make capturing a picture from the device camera (webcam) easy?
|
# ? Oct 26, 2020 22:20 |
|
kiwid posted:Are there any JS packages out there that make capturing a picture from the device camera (webcam) easy? I mean, this doesn't seem that hard? https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Taking_still_photos
|
# ? Oct 26, 2020 22:59 |
|
He probably meant node.
|
# ? Oct 27, 2020 00:26 |
|
For whatever reason cloudflare doesn't like this code, so image it is. I'm building a websocket powered application. I'd like to wrap the raw client with a helper function. Clearly what I'm doing in that last line is wrong. What would be the best way in a React app to hook into incoming messages like this, following the structure I've setup? huhu fucked around with this message at 04:41 on Oct 27, 2020 |
# ? Oct 27, 2020 03:27 |
|
huhu posted:For whatever reason cloudflare doesn't like this code, so image it is. So where's the definition of my_func?
|
# ? Oct 28, 2020 06:32 |
|
Is it just me or is it annoyingly hard/frustrating, atleast as a newbie, to connect a sql database to Javascript? Am I just doing something wrong? I can't even find a straight answer on how to do it
|
# ? Nov 1, 2020 02:46 |
|
You’ll have to find a “web scale” SQL server, I’m sure there are some out there. In NoSQL land it’s trivial for access, especially for things like CouchDB where the index can itself be written in JavaScript.
|
# ? Nov 1, 2020 02:53 |
|
Yeah I'm trying to tie into postgres, but I'm probably just way in over my head. Just trying to make a simple form that creates data on a database. I set it up with Mongo which seemed stupidly easy but this is just "whaaa"
|
# ? Nov 1, 2020 02:54 |
|
Empress Brosephine posted:Is it just me or is it annoyingly hard/frustrating, atleast as a newbie, to connect a sql database to Javascript? Am I just doing something wrong? I can't even find a straight answer on how to do it node-postgres is dead easy to use for a Node server. JavaScript code:
Empress Brosephine posted:Yeah I'm trying to tie into postgres, but I'm probably just way in over my head. Just trying to make a simple form that creates data on a database. I set it up with Mongo which seemed stupidly easy but this is just "whaaa" It sounds like you're trying to do this entirely from a frontend, but you generally need a server in the middle for basic security and access control reasons. The closest thing to an exception is row-level security like Postgres has, or similar functionality with services like Firebase, and in that case you need to build out authentication and security management before you do anything else. Roadie fucked around with this message at 03:22 on Nov 1, 2020 |
# ? Nov 1, 2020 03:15 |
|
I'll check them out bi wasn't too concerned with authentication since it would be used Internally. I should probably just look into MS Access lol
|
# ? Nov 1, 2020 04:11 |
|
i dont know anything about ms access but setting up a node server is extremely easy with libraries/frameworks like express
|
# ? Nov 1, 2020 14:03 |
|
Empress Brosephine posted:I should probably just look into MS Access lol No, don’t,
|
# ? Nov 1, 2020 22:11 |
Roadie posted:node-postgres is dead easy to use for a Node server.
|
|
# ? Nov 2, 2020 15:31 |
|
Osmosisch posted:Yeah node postgres is fine. Don't connect directly to database from browser please. Or this
|
# ? Nov 2, 2020 16:04 |
|
edit: Hm, I think I found what the issue is for the second and third (IE JS not supporting the ellipsis spread 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. Might be okay to ignore this since presumably people are using Edge now instead of IE usually, hm. I'm getting syntax errors from a couple lines in IE that don't give errors in either Firefox or Chrome. The lines in question: code:
code:
edit: There's also a third one where a function is defined that gives the error "expected ')'" which seems strange given there's definitely a closing parenthesis there (and there's no similar error in firefox or chrome): code:
Ytlaya fucked around with this message at 21:18 on Nov 12, 2020 |
# ? Nov 12, 2020 20:56 |
|
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.
|
# ? Nov 12, 2020 21:09 |
|
Probably works in Edge though
|
# ? Nov 12, 2020 21:18 |
|
What's a decent and common UI toolkit package for Electron? For creating desktop apps, or something that looks like it. I'd like to tinker around and evaluate it.
|
# ? Nov 16, 2020 20:21 |
|
I use vue + element-ui a lot
|
# ? Nov 16, 2020 20:29 |
|
I'm a JS noob and we're using window.fetch to call a web api to retrieve some data. Some of this rarely changes, so I'm trying to implement a cache, and trying to figure out how to do expiration, but it occurred to me that this functionality might be built-in in the browser. Am I wasting my time? I can't seem to find a time stamp on the requests, so I'm not sure if I'm missing something, or if I have to do this myself.code:
|
# ? Nov 24, 2020 11:30 |
|
A lot of webapis are written by totally incompetent developers such that they do not process etags or If-Modified-Since headers, so it can quite frequently be a good idea. However note in modern practice you should write the app to not care and control the caching more in a service worker. If you can try and use the semantics of offline-first, i.e. serving from cache then running a refresh request in the background. Note Cache is a thing already in browser world.
|
# ? Nov 24, 2020 17:27 |
|
I'll just dump this here because https://www.youtube.com/watch?v=mUFFbObqNFY
|
# ? Nov 24, 2020 22:02 |
|
Currently moving a hodge podge of unstructured js code to typescript, and pulling my hair out
|
# ? Nov 28, 2020 21:31 |
|
How many load-bearing bugs did you unearth so far?
|
# ? Nov 28, 2020 22:14 |
|
n3m6 posted:Currently moving a hodge podge of unstructured js code to typescript, and pulling my hair out any.
|
# ? Nov 30, 2020 09:39 |
Ape Fist posted:any. that's for the times that you want to pretend you converted something to typescript, not for when you really are converting
|
|
# ? Nov 30, 2020 14:08 |
|
Jazerus posted:that's for the times that you want to pretend you converted something to typescript, not for when you really are converting It's sometimes for getting it to stop yelling at you so that you can then actually begin converting. But usually it's just a // TODO: properly type this that stays there forever.
|
# ? Nov 30, 2020 18:53 |
|
I’ll use any when prototyping something, then I spend twice as long fixing type issues as I did writing the function in the first place
|
# ? Nov 30, 2020 18:56 |
|
Jazerus posted:that's for the times that you want to pretend you converted something to typescript, not for when you really are converting i've gone through the exercise of taking vanilla js and doing stuff like adding google closure annotations or turning it into typescript several times. once you hit, say, 50~100k loc, it probably will take you longer to annotate the library than it did to write it in the first place, and you're better off rewriting it clean room, unless the original developer wrote really clean, easy to understand code that was mostly static methods and didn't use custom types as parameters (spoiler alert, they didn't).
|
# ? Nov 30, 2020 19:10 |
|
a cool thing about converting JS to TS is getting your coworkers to review the code so you can merge it I post these PRs in slack on a weekly basis. also have brought up that we have a serious problem with lack PR review on this team in retro multiple times I refuse to merge without ppl looking at the code b/c people need to learn this poo poo.
|
# ? Nov 30, 2020 19:52 |
|
Still a typescript newb. I am working with typescript and antd for front end design work. Can someone tell me why when trying to align my columns in a table this doesn't work: code:
code:
|
# ? Dec 3, 2020 20:55 |
|
Skyarb posted:Still a typescript newb. I am working with typescript and antd for front end design work. The compiler doesn’t infer string literal types from strings, so in the first snippet it sees just “a string” where a literal type is expected. With the assertion in the second snippet, you are telling the compiler that it is the expected type, and so it passes. Instead of the specific type name in these situations, you can use ‘as const’ for the same effect.
|
# ? Dec 3, 2020 21:22 |
|
|
# ? Jun 3, 2024 21:55 |
|
skull mask mcgee posted:The compiler doesn’t infer string literal types from strings, so in the first snippet it sees just “a string” where a literal type is expected. With the assertion in the second snippet, you are telling the compiler that it is the expected type, and so it passes. I am still confused, I am sorry. What are string literal types? I thought a type could only be a string?
|
# ? Dec 4, 2020 03:47 |