Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 09:57
    ablomen opened #35082
  • 09:29
    mzeiher opened #35081
  • 09:21
    n-filatov opened #35080
  • 09:04
    bre1470 edited #33749
  • 09:03
    bre1470 reopened #33749
  • 08:06
    quin opened #35079
  • 06:22
    mjbvz opened #35078
  • 05:32
    lirbank edited #35077
  • 05:26
    lirbank opened #35077
  • 04:47
    TroyTae edited #35076
  • 04:46
    TroyTae opened #35076
  • 04:28
    typescript-bot opened #35075
  • 01:50
    lephuongbg opened #35074
  • 01:46
    amcasey opened #35073
  • 01:21
    cheblin opened #35072
  • 01:17
    falsandtru edited #35071
  • 01:03
    jack-williams synchronize #35065
  • 00:50
    falsandtru edited #35071
  • 00:46
    jack-williams synchronize #35065
  • 00:14
    falsandtru edited #35071
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”
anthalon
@anthalon
yup, that's what I'm after. Thanks
Thanzex
@Thanzex
What are the best practices to export constants from a package?
Anthony Lukach
@alukach

Does TS not allow typing a function without directly calling it?

e.g.

[{x: 1}].map(Object.entries<number>) // 'number' only refers to a type, but is being used as a value here.
Bruce Pascoe
@fatcerberus
Yeah, you can’t instantiate the generic without calling the function, we were discussing that here recently
Keith Layne
@keithlayne
if you could....
Bruce Pascoe
@fatcerberus
It actually seems like it’s interpreting the angle brackets as comparison operators there, which is odd
Anthony Lukach
@alukach
Is it clear what I'm trying to do? This would be helpful for composing "point free" functions (I'm using ramda). WIthout adding a type to Object.entries, TS thinkings the 1 index of the tuple is any rather than number... Is there a way to achieve my goal?
Keith Layne
@keithlayne
yeah, we all understand what you want
Anthony Lukach
@alukach
Keith Layne
@keithlayne
write a lambda where you specify the type
Anthony Lukach
@alukach
well that's not much fun, but if that's the way it has to be...
Keith Layne
@keithlayne
for your own functions you can sort of work around by writing a generic interface with a call signature.
Bruce Pascoe
@fatcerberus
The compiler sees a syntax error in reality but it always tries to recover and emit valid code so that makes sense
Keith Layne
@keithlayne
whoosh
Bruce Pascoe
@fatcerberus
Huh?
Anthony Lukach
@alukach
@fatcerberus :thumbsup: Oops, I spaced the error about Property 'entries' does not exist on type 'ObjectConstructor'.
Thanzex
@Thanzex

I'm trying to create a package to export some constants and interfaces that we need for a project. The interfaces work just fine, but trying to import and use one of the exported constants gives an error in compilation with webpack.
WARNING in ./src/app/app.component.ts 6:17-20 "export 'CONSTANT' was not found in 'package'
My package is made of:
constants.ts

export const TEST="test";

index.js

import { TEST } from './constants'

module.exports = { TEST }

index.d.ts

export { TEST} from './constants'

After searching for a while i found webpack/webpack#7378 that seems to dive into the problem but i haven't found a soultion yet.
Any ideas?

Keith Layne
@keithlayne
you need to export { TEST } from './constants'
Thanzex
@Thanzex
yup sorry, i re-wrote everything for the message, there are no typos
Keith Layne
@keithlayne
and in the types. Not sure what your mixed case meant. Okay.
Do you have a constants.d.ts?
and are you exporting the constant in JS somewhere?
Thanzex
@Thanzex
in the message i forgot to add the module exports in the js file
@keithlayne what do you mean?
i do not have a constants.d.ts
Keith Layne
@keithlayne
well you're referencing it.
Thanzex
@Thanzex
i do have many more files that contain only interfaces without the *.d.ts file and they work fine with this setup
Keith Layne
@keithlayne
are you writing in mixed js/ts?