Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 20:00
    typescript-bot closed #35110
  • 20:00
    typescript-bot closed #35412
  • 20:00
    typescript-bot closed #35646
  • 14:50
    DanTsk edited #35688
  • 14:50
    Jack-Works edited #35148
  • 14:50
    DanTsk edited #35688
  • 14:48
    Jack-Works synchronize #35148
  • 14:34
    Jack-Works edited #35148
  • 14:32
    Jack-Works edited #35148
  • 14:08
    Jack-Works edited #35148
  • 14:05
    Jack-Works edited #35148
  • 13:39
    DanTsk edited #35688
  • 13:23
    DanTsk edited #35688
  • 13:23
    DanTsk opened #35688
  • 11:06
    typescript-bot opened #35687
  • 10:57
    Jack-Works edited #35148
  • 10:55
    Jack-Works edited #35148
  • 10:54
    Jack-Works edited #35148
  • 10:54
    Jack-Works synchronize #35148
  • 10:36
    weswigham synchronize #15575
Shanon Jackson
@ShanonJackson
try what i linked.
TNThacker2015
@TNThacker2015
alright
Shanon Jackson
@ShanonJackson
or sorry maybe with brackets
updated it
TNThacker2015
@TNThacker2015
I tried what you linked, but it gives a string type instead of a union.
Is there a way for it to be a union?
Shanon Jackson
@ShanonJackson
ahh yeah its because object literals always assume mutation, therefore they don't type {a: "bar"} as a constant they type it as {a: string}
basically you have a few options all of them involve giving the compiler more information
const objArr = [{ a: "e" as const, b: 2 }, { a: "foo" as const, b: 100 }, { a: "bar" as const, b: 100 }]

type GetA = (typeof objArr)[number]["a"] // "e" | "foo" | "bar"
const objArr = [{ a: "e", b: 2 }, { a: "foo", b: 100 }, { a: "bar", b: 100 }] as const
or using some kind of function that infers the string iteral type and not 'string' when creating an object
TNThacker2015
@TNThacker2015
that worked, thanks! :)
Shanon Jackson
@ShanonJackson
no problem
Bruce Pascoe
@fatcerberus
I’m very confused by this comment, it seems like a non sequitur https://github.com/microsoft/TypeScript/issues/34534#issuecomment-543408917
I’m not your mom, right?
What.
Keith Layne
@keithlayne
Bob's your uncle.
Bruce Pascoe
@fatcerberus
But that guy sucks
garyking
@garyking
Does anyone know how to generate a .d.ts file for a JS project that uses JSDoc, automatically? Rather than need to write it by hand, for a module.
garyking
@garyking
I'm assuming you can really only generate one by hand, which is what I've been doing so far. I'm checking this out but I've already encountered so many bugs.
Bugs which seem to mostly do with JSDoc itself.
Gerrit Birkeland
@Gerrit0
Can't you use tsc with --emitDeclarationOnly?
Keith Layne
@keithlayne
yeah allowJs and declarations are supposed to no longer be incompatible.
AnyhowStep
@AnyhowStep
Is there even a point in banning him
He'd just create another account and throw another hissy fit
Edoardo Luppi
@lppedd

Quick style question. To convert a any value to a boolean, do you prefer

Boolean(value) \\ or
!!value

Just curious. I prefer the explicit Boolean(...) alternative.

Tõnis Ostrat
@tonisostrat
depends on the context
AnyhowStep
@AnyhowStep
I prefer if (typeof value != "boolean") { throw new Error(); }
Orta
@orta
@keithlayne - re: TS in web app - yeah the default TS support with monaco only supports editing one file
You’d need to make the virtual host support more files etc
is a pretty good example of it
Keith Layne
@keithlayne
thanks
Orta
@orta
Wow, I didn’t really know how bad android support in monaco is
you really can’t even delete
AnyhowStep
@AnyhowStep
¯_(ツ)_/¯
Why do you think I keep bugging you all for better mobile support =P
Keith Layne
@keithlayne
your dude is missing an arm
Bruce Pascoe
@fatcerberus
@orta It’s not too nice on iOS either, there’s literally no way to pull up the copy/paste UI because the custom context menu overrides it
Orta
@orta
I’m fighting the desire to go fix some of the worst offenders in monaco itself
Bruce Pascoe
@fatcerberus
@AnyhowStep ban who? I don’t know see what that was in response to
Keith Layne
@keithlayne
to the your mom dude on github
Bruce Pascoe
@fatcerberus
Oh
anthalon
@anthalon

I have an object that accepts a string parameter in it's constructor, and it's toString() formats that string in a specific way.

for instance:

export class Currency
{
    constructor(private amt: string) {}
    ...
    toString() { /* return formatted string here, comma separated etc */ }
}

amd if I use an object of this class directly, it returns the formatted string.

But when I try to parse from json, the Currency object is treated as string, and doesn't format with it's toString() method.

How can I initialize this object from json so that it's treated as a Currency object?
Keith Layne
@keithlayne
you probably know this, but that has nothing to do with TS. You're going to have to write some kind of deserialization function.
anthalon
@anthalon
the Currency class is part of a model, and it's being given a string value when the json is JSON.parsed. Instead of doing this manually, I was wondering if typescript offers some functionality to initialize these objects, maybe in a way where the string is not assigned to the object, but instead passed in as a constructor parameter?
Bruce Pascoe
@fatcerberus
All the functionality typescript adds is compile-time only, it doesn’t help you at runtime
What I think you want is a “reviver”, google “json reviver”