« first day (4436 days earlier)      last day (504 days later) » 

7:08 AM
Both ways work, which way should it be written?
1)
    addedPlayerVars.forEach(function(apv, i) {
    players.add(".playSingle" + i, apv);
  });

2)
    addedPlayerVars.forEach(function(apv, i) {
    players.add(".playSingle" + i, addedPlayerVars [i]);
  });
 
1)
 
Thank you.
 
lv_
7:32 AM
Hi, is anyone here? can I ask a question about typescript
 
@lv_ Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
 
2 hours later…
9:16 AM
Hello
 
@codingmaster398 Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
just seeing if you can use <b>HTML</b> here
righty-o, ta-ta
 
9:53 AM
@lv_ yes TS is OK
 
10:20 AM
When I use "Object.setPrototypeOf;", no error appears while writing the script, but it shows error when I compile with tsc command even if my tsconfig file settings are correct. I checked this issue in typescript playground, it shows no error.
error TS2550: Property 'setPrototypeOf' does not exist on type 'ObjectConstructor'. Do you nee
d to change your target library? Try changing the 'lib' compiler option to 'es2015' or later.
 
10:40 AM
How are you using tsc? Some invocations will ignore your configuration. IIRC, if you directly point to a file: tsc index.ts will only use the default configuration, not the one in your project. You'd need to pass extra configuration either with commanline flags or set the configuration file to use. Plain tsc over a directory should work with the configuration in that directory, I think.
 
lv_
@VLAZ Thanks, I post a question here: stackoverflow.com/questions/74726959/… , There is some answer, but I still want to know is there some different way to solve this, please check.
 
You either need to handle missing values or not.
It's a fact in programming.
If you don't want missing values, then make sure your data doesn't have those. You can add defaults, if needed. But if you already have data that has potentially missing values, then you can only change how you handle it at each call site.
There is no magic the compiler can do where you say "I have this data where a value is potentially missing. Just fix it for me"
 
11:16 AM
@DamodaraSahu likely what @VLAZ said: the config used in the Playground and IDE differs from the one that tsc gets. Use the --showConfig CLI option to inspect what is actually used. It is highly likely you need to pass --project to the invocation
@lv_ you will have to choose between making info a required property or add optional chaining. No other way around it. As a remedy to avoid making a lot of code changes, which is understandable, you can make a helper that iterates over your books and initializes info to an object (what to do with info.name is up to you) before passing the array down the pipeline.
 
11:33 AM
@OlegValteriswithUkraine I am using typescript installed globally, but tsconfig file generated locally. I changed some options in tsconfig file and checked with 'tsc --showConfig' command, the output in later case updates. This means tsc gets same settings defined in tsconfig file.
And I checked with typescript playground, tsconfig settings, couldn't able to generate such error in it.
 
 
1 hour later…
1:05 PM
@DamodaraSahu hmm. What happens if you explicitly force it to use the tsconfig you supplied?
 
1:39 PM
posted on December 08, 2022 by Ben Mason

Hi everyone! We've just released Chrome Beta 109 (109.0.5414.34) for Android. It's now available on Google Play. You can see a partial list of the changes in the Git log. For details on new features, check out the Chromium blog, and for details on web platform updates, check here. If you find a new issue, please let us know by filing a bug. Krishna Govind Google Chrome

posted on December 08, 2022 by Ben Mason

Hi everyone! We've just released Chrome Beta 109 (109.0.5414.33) for iOS; it'll become available on App Store in the next few days. You can see a partial list of the changes in the Git log. If you find a new issue, please let us know by filing a bug. Erhu Akpobaro Google Chrome

 
@OlegValteriswithUkraine how to do that?
 
2:08 PM
@DamodaraSahu pass the psth to tsconfig to the --project CLI option
are you invoking tsc directly, btw, or is it via an npm script? and is the project structure flat (meaning is tsconfig in the same directory as project.json?) if it is the latter?
 
2:35 PM
How would this .forEach be changed to use for loop instead?

It would go from this to what?
playerVarsList.forEach(pvl => {
    players.add(".playSingle" + pvl.index, pvl.player)
  });
Is that able to be done here?
 
3:37 PM
I'm learning express js, is it a replacement for PHP?
I mean, could it be?
 
not express.js itself
but the node.js... "ecosystem" can solve all the problems php can solve
 
@VLAZ does es6+ have typings?
 
No
 
@KevinB for a few reasons I might switch some projects to nodejs
 
Because a phone can successfully hammer in a nail, doesn't mean you should use it for that purpose
 
3:40 PM
There is an initiative the TS developers have started with TC39 to integrate types into runtime but that's very far off from being reality. I think they just announced they had plans for this and it was this year.
 
what if the phone is a kyocera?
Can you make a HTMLElement contain none HTML code?
 
@MarySmithJames playerVarsList.forEach(pvl => { should just be for (const pvl of playerVarsList) That's about it. Fix the brackets, too.
 
For example, if I want to use a PHP tag
 
Like in the browser?
 
The code will not be render but will be used to get the outerHTML
Example:
var element = new HTMLDivElement()
element.innerHTML = "<?php echo('hello world') ?>";
log(element.outerHTML);
<div><?php echo('hello world')</div>
and the reverse:
<?php echo('hello world') ?>
   <div></div>
</?>
 
3:51 PM
the php code has no meaning if this is client-side
if it's server-side, the html code has no meaning
 
I want to see if the DOM object will allow me to build a document model but I don't need it to be rendered
 
this line of questioning makes no sense
 
it's about building the document model not so much rendering it
 
where
 
^?
 
3:52 PM
the browser
but i don't need to render it
 
mr5
@VLAZ saw that too and it seems of TS/JS devs suggests JS is better of without types. JS is way behind too. I also think introducing types to a dynamic language will slow down the interpretation phase
 
fi you don't need to render it, why do you need to create it
 
OK, then you can do it. The PHP tags just won't be parsed ever.
You'd get the DOM tree and the content will be something that's technically text.
 
that's ok. i'm working on examples that wont be rendered
 
mr5
@1.21gigawatts maybe you mean to manipulate strings?
 
3:55 PM
@mr5 Depends. They'd have to be optional - no way around this, as the code should be backwards compatible. So maybe you'd need special mode to run them in. Just how we have strict mode, there could be typed mode. So you can opt into this in some parts of the code.
 
@mr5 i would argue that those devs might not know or have used a strongly typed language
@VLAZ good idea. if it's forced then you'll have people arguing against it
 
If it's forced then old code cannot conform.
 
if it's optional, and that's the suggestion, then it allows devs to learn as they go
 
And will break the web.
BTW, Python is dynamic but strongly typed. So, that's not a new concept. It also has optional type annotations but I don't actually know how they work.
 
I'm not a fan of adding things to the js language unless it obsoletes at least 10k packages per avg node_modules folder
 
3:59 PM
that's the proposal. the proposal is to have JS engines ignore types by treating them as comments in the short term and then add full typing in the long term
so in the following code:
var age: number = 100;
 
var?
 
mr5
@VLAZ yeah, that or just add more languages for the browser to support
 
and why would age be hardcoded to 100
 
the browser JIT will match ":" and then anything after that up to the "=" would be a comment
 
how are you gonna tell old browser/systems to interpret that?
Phones from 5 years ago?
8 years ago?
 
4:03 PM
it would probably be the same situation as any other browser feature in that you have to know your audience or reach critical mass -> can i use
 
IE
 
just dumb
it's already an optional feature
if you want typings use ts
 
the issue i have is that i'm learning NPM and modules
and none of them have typings or pick up typings
i'm already using Typescript
 
use stuff that does
most things worth using have typings
 
4:05 PM
@KevinB they have to have d.ts created for it
 
right
and most things worth using have them
 
if you have strong typing in the language you get it for free
 
@1.21gigawatts Here is a problem I see here - ES6+ code can be transpiled to lower level code which is equivalent. E.g., 1_000_000 can just be 1000000. But runtime level types cannot be downlevelled. If that happens function foo(x: number) {} starts accepting non-numbers. So you get split functionality. Some users get the type-correct code, others the unsafe code.
 
How would this one be converted to .forEach?
 
if you have strong typing in your language then vscode can give you intellisense. that is show you all properties and methods as you type, it can do type checking as you code, it can show documentation and so
 
4:07 PM
  for(let i = 0; i < 96; i++) {
players.add(".playSingle" + i, (playerVarsList[i] || {}));
}
I was having difficulty with this one.
 
what happens is when you transpile it down you end up with funciton foo (x) { /* code that enforces type on x or throws an error / / your function code */
 
You can enforce this on older environments but it starts burdening the system. You need can have a validation wrapper so you get something like foo = validateNumber(function foo(x) {}) which starts changing the semantics of the code.
 
so effectively every project that wants to ensure users who aren't on the latest version can see their app have their built-code suddenly increase in size by a large amount
 
2 days ago, by VLAZ
@MarySmithJames .forEach() is when you have an array and want to execute something for each item. You don't have an array here. Unless 96 is supposed to be the length of one but it's not evident. If you just want to create an array of 96 items, you can use Array.from({ length: 96 }, (_, i) => ".playSingle" + (i +1)) However, this is not fully equivalent, as it creates, doesn't add to an already existing array with data.
 
all just to re-implement an existing feature
 
4:10 PM
@VLAZ i think of it this way. there's the world with billions of users with browsers from netscape navigator up to chrome release candidate
 
presumably playerVarsList is an array
and 96 is the hardcoded length
 
but if you are making an application for an enterprise then you can say everyone needs a browser from 2022 to use this app
you have a controlled environment that you don't have to worry about supporting the lowest common denominator
 
@1.21gigawatts No, don't get me wrong - I'm OK with introducing types at runtime. Should be fine. However, adding the TS grammar is what I find problematic.
 
normally, that situation consists of this is an enterprise and we need to support department X that's still using IE10... not the other way around.
 
then you can say, 'let's use JS 2022 that has types and get all the benefits from it'
 
4:12 PM
If you want a very concrete example why adding the TS grammar to JS is a problem, consider this code:
||> console.log(new Map<String, Number>([]))
 
@VLAZ undefined Logged: [ 'true', 'true' ] Took: 1ms
 
@KevinB yep. and probably because they have legacy app that only works in ie 10. thats a problem. in the old days we would put, "You need IE 4 to use this app" at the top the page. but you can also say, "this works in chrome install and use that for our site"
 
This is JavaScript. Valid, albeit misleading, JavaScript.
 
mr5
@1.21gigawatts how would you stop people from accessing the URL?
 
by having error handling that detects the error and presents a message.
 
mr5
4:15 PM
and would he use the language with types or not?
 
@mr5 not following. but back then you could get window.navigator and it would tell you the exact name of the browser and then return out of your code before running it. yes it would error if trying to run it. or later you do feature detection
 
Don't be like godaddy and tell all your users "You're using an out of date browser!" when they're using the latest version of whatever browser they're using, and godaddy is just wrong because they're relying on useragents.
 
or you can do a noscript tag:
 
@1.21gigawatts If you're making an application like that, you've re-discovered IE. IMO, if it needs that tightly controlled, it's not a web application. It is basically a disguised desktop application.
 
<noscript>You need Javascript installed</noscript>
 
4:16 PM
noscript doesn't solve the problem
this isn't a case of javascript being turned off
 
mr5
try { runCodeWithTypes() }
catch { notUsingLatestBrowser() }
 
@VLAZ one idea is to simply take the regex patterns for matching from the typed language (typescript) and put them into the non typed language (javascript) and then discard the types
 
@mr5 IE again.
 
when the code within runCodeWithTypes isn't valid javascript as described by the browser running, you can't guarentee that it doesn't also break notUsingLatestBrowser
 
Like, seriously - code written to account for IE would look like that: try { goodCode() } catch { badHackyIECode() } I'm not even joking.
 
mr5
4:19 PM
@VLAZ you mean, you're concerned IE will interpret this differently?
 
Or it would try to detect the browser and call good/bad code.
 
we've been down this road before
allthat will happen is jquery will be updated
 
@mr5 No, I mean that's re-introducing IE into the web.
The reason it was bad is because it used different rules for the code. And you often had to write the code twice - once for IE, once for sane browsers.
 
tldr new features will result in new packages being needed to account for those features not existing, and we're back in the "lets just throw more packages at it" scenario
 
what i'm saying is browsers should add support for typing in JS, and like every other feature, it wouldn't be usable unless the browser supported it. if the company or the developer wanted to support a wider audience then of course they could make two versions or have something strip out the types in javascript
 
4:22 PM
9 times out of 10 what that results in i sall code is written for the lowest common denominator
 
This was a MAJOR problem plaguing web development and a strong reason why it's in shambles today . Microsoft have large and direct responsibility for this.
 
my exact use case is for node packages and javascript libraries
 
you'll just transpile down to one version of the code that works on all of them
that happens to not even use the new features
the alternative would mean literally doubling the size of your code
 
the reasons i don't specifically like typings d.ts is that they get out of date. if you have a js library and strongly type it then that is all you have to do
 
that's not a typings problem
that's a JS ecosystem problem
 
4:23 PM
^ this
 
see my last reply
 
And I'm not going to stop blaming IE for a lot of that.
 
that problem exists outside of using typescript
 
if you have strongly typed code you don't have to write typing files. you get it for free
 
the typings file is just one piece of the puzzle
one that most companies worth their salt include in their packages anyway
 
4:25 PM
You can generate the typings file out of the code with types, no?
I've not done it but I thought it's possible.
The typings file needs to be written from scratch for libraries that don't have types. E.g., jQuery which is written in plain JS.
 
i wrote live dynamic code completion, class lookup, type safety and many other features for a project using reflection. i don't know how vscode does it
 
like, there's probably been one, maybe two packages i've ever used that didn't have types available somewhere
 
loop over your array with foreach
!!mdn array foreach
 
4:27 PM
how would that be written?
 
myArray.forEach(() => dostuff())
 
Is using app.locals a good way to persist a global object in nodejs or expressjs?
app.locals({
    site: {
        title: 'ExpressBootstrapEJS',
        description: 'A boilerplate for a simple web application with a Node.JS and Express backend, with an EJS template with using Twitter Bootstrap.'
    },
    author: {
        name: 'Cory Gross',
        contact: 'CoryG89@gmail.com'
    }
});
 
@1.21gigawatts Please don't post unformatted code - use the up arrow to edit your post, then hit Ctrl + K to format the code in that post. See the faq. You have 25 seconds to edit and format your message properly before it will be removed. Please separate code blocks from your actual question. Put your question in 1 message and then your code in a 2nd and format it.
For posting large code blocks, use a paste site like like gist.github.com, hastebin.com, pastie.org or a demo site like jsbin.com
 
mr5
@1.21gigawatts I think it's not specific to "app.locals". I see it used for window object, and some uses their own global object like module. You can start by declaring one global object or reuse an existing one.
 
that looks like static content
not data that needs to be persisted
 
4:33 PM
posted on December 08, 2022 by Ben Mason

Hi everyone! We've just released Chrome Dev 110 (110.0.5462.3) for Android. It's now available on Google Play. You can see a partial list of the changes in the Git log. For details on new features, check out the Chromium blog, and for details on web platform updates, check here. If you find a new issue, please let us know by filing a bug. Krishna Govind Google Chrome

 
:55662437   playerVarsList.forEach((pvl, i) =>  {
    players.add(".playSingle" + i, pvl);
  });
Uncaught TypeError: playerVarsList.forEach is not a function"
 
then what is playerVarsList
i hate playing 20 questions
 
let playerVarsList = {
 
if you want to iterate over it, ideally it shouldn't be an object
 
mr5
it needs to be []
 
4:41 PM
but you can iterate over object keys if that's a must
 
@mr5 I don't see my global in my module
 
Object.keys(myObject) gives you an array
you can forEach an array
similarly there's a method to get the values
 
In my app.ts:
const sessions: Sessions = getSessions();
 
export myglobals { /* globals here */ }
import it where you need it
now it can be used both in and out of express
 
mr5
4:43 PM
@MarySmithJames tell me this transition animation is a school project
 
I changed to this:
export const sessions: Sessions = getSessions();
No errors
In my module there is an error:
 import sessions from "./server"
Nevermind. it works with { sessions }
 
import foo - uses the default export, import { foo } - the export named foo
To make a default export export default 42;
When you import the default export, you can name it however you like. Similar how if you have a function that returns a person, you can do const bob = getPerson() since the variable name is arbitrary. But if you want a specific property, const {name} = getPerson() you need to use the correct name.
 
got it
When using JSON is there a way to return the value formatted without using stringify on every call? Here's what I'm doing now:
 response.json(JSON.stringify(data, null, 3));
 
4:59 PM
from fetch()?
Wait, you probably mean from express
 
yeah i've updated it
nevermind I should format it if i need to on the client
 
mr5
heyya people, what's the difference between summary and overview? definition I found on web is still confusing
 
There is probably some way to hook into it. But I'd personally not bother.
@mr5 Probably nothing. But might depend on context.
 
mr5
ic
our lead dev already reviewed my tech design
but I'm revising my "summary" section for the CTO
I think I better split my summary section because it's too long to be a summary
 
to whoever made the timeline feature in vscode thank you
it just saved my butt
 
5:12 PM
@mr5 Yeah, summary tends to be short. You can call it "overview" and have it be, for example, 2-3 paragraphs.
Won't be as jarring.
Although, calling it "summary" can also probably work.
Scientific papers would call such a section "abstract". It's sort of the summary/overview of the whole paper.
It is not too long but it does introduce the subject, what was done (e.g., experiments or research) and outlines what the results are.
 
mr5
for me, this is the most stressful part of being a dev, documenting what you know / have investigated
never experienced this before, only now in my current employer
I tend to only contain the information in my mind, so explaining everything is a bit new for me
is anyone familiar with keycloak-connect-nodejs?
Is it common for IdP middleware to redirect SP back to IdP domain to ensure users are logged in? Because if you're using keycloak as IdP, they do the redirect
not sure where they based this logic, is it from standard?
 
6:18 PM
I don't
So the file handler of fs.writeFile on nodejs doesn't tell you what file it saved?
 fs.writeFile(uploadFilePath, file.buffer, this.fileSaveHandler);
 fileSaveHandler(error: any = null) {
It only returns an error? How do you know what file you saved?
 
i mean
presumably the file is in uploadFilePath
that's just an error callback
 
my situation is i'm saving 100 files and i don't want to lock up the ui so i'm saving async
but i don't want to create anonymous callback function for save
 
use the promise syntax
 
good luck
;)
 
6:23 PM
thanks
 
you can use the factory method
but in the end, it's just creating anonymous functions with an extra step
if you want your callback to have info, you need to give it info
it can't be a closure and access info with the current context if it is defined elsewhere
 
so it's impossible to get information about the file the way i have the handler setup...
 
no, not at all
it's impossible to do so with the restrictions you're placing on the process
There are correct ways to both do it with promises, and callback style
but you've decided not to use anonymous functions, so that kills most possible solutions
 
i have other code in the handler that i call from other places
so i don't want to duplicate code
 
using an anonymous function doesn't mean duplicating that code
 
6:32 PM
anonymous functions create other proglems
 
fs.writeFile(uploadFilePath, file.buffer, err => this.fileSaveHandler(err, {uploadFilePath, file}));
 
if i'm in a for loop then the reference is the last file in the loop
 
no
that's because you're using var
don't use var
 
const?
 
const or let
const if you never change the value, let if you do
start with const, and if it errors, you know you need let
4
 
6:39 PM
posted on December 08, 2022 by Prudhvikumar Bommana

The Beta channel has been updated to 109.0.5414.36 for Windows, Mac and Linux . A full list of changes in this build is available in the log. Interested in switching release channels? Find out how here. If you find a new issues, please let us know by filing a bug. The community help forum is also a great place to reach out for help or learn about common issues. Prudhvikumar Bommana Google Chr

 
7:20 PM
These days I pretty much never use let. It's almost exclusively in for (let i = 0; i < something; i++). Somewhat rare but also in other loops. And also rare for let x; if (cond) x = 1; else x = 2; but even that can be avoided.
 
7:34 PM
@OlegValteriswithUkraine this might be of interest: handling async failures later:
const wrapPromise = p =>
    p.then(
        value => ({ status: "fulfilled", value }),
        reason => ({ status: "rejected", reason })
    );

const unwrapPromise = p =>
  p.then((result) => {
    const {status, value, reason} = result;

    if (status === "fulfilled")
      return value;
    else if (status === "rejected")
      throw reason;

    throw new Error(`Unknown status ${status}, the value of the promise was ${result}`);
  });
this allows you to do
const pending = wrapPromise(fn());
/ * later */
const result = await unwrapPromise(pending);
Useful if you might want to set off an async task then come back to it but then don't have unhandled promise rejections around:
const pending = wrapPromise(fn());
try {
    const takesAWhile = crunch();
    const result = await unwrapPromise(pending);
} catch(err)  {/* handle either error */}
It might be obvious in hindsight but it didn't really occur to me to do this until now. And it's using the pattern with status/value/reason from Promise.allSettled() so definitely not something I've just come up with. I was making a promise wrapper and I just re-used it when I realised it was already there.
And yeah, I guess you can also re-write the first function to just wrapPromise = p => Promise.allSettled([p]).then(([p]) => p) but it is aesthetically unpleasant to me.
 
7:51 PM
Why can't I use a key value object like this in Typescript?
var mydictionary = {}
mydictionary[mystring] = myobject;
mydictionary[mystring2] = myobject2;
 
Yes, why can't you use that
i can
 
@1.21gigawatts You need to specify that the object can have arbitrary keys. That's what Record is for.
 
i mean i can use it but
ok so it type checks
var mydictionary: Record<string, MyDataType> = {};
mydictionary[mystring] = myDataType1;
mydictionary[mystring2] = myDataType12;
 
8:12 PM
Just be careful myDictionary.foo will be typed as MyDataType but it doesn't necessarily going to exist. There is a compiler option to force stricter checks. Let me find it.
noUncheckedIndexedAccess will make the result T | undefined which is safer.
 
 
3 hours later…
11:14 PM
yo guys
 
whoa
 
how come the copy to clipboard function in js works on my laptop's browsers (doesnt matter which), but doesnt work when i try it with my mobile's browsers?
navigator.clipboard.writeText is what i used
 
that's a browser feature
different browsers have different implementations
 
is there an overall solution for both?
im confused tho because i tested with the same browsers on my laptop
 
that is meant to be it
but i'm not confident in the reliability of mobile browsers following standards
 
11:18 PM
very weird
 
You are doing this in response to user interaction, right?
directly?
 
yes, onclick once a user clicked / tapped the "Copy" button
 
:shrug:
 
11:54 PM
What's better? Tabs or spaces?
 

« first day (4436 days earlier)      last day (504 days later) »