by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 13:46
    BobNobrain opened #38963
  • 12:39
    andreialecu closed #38962
  • 12:39
    andreialecu closed #38959
  • 11:56
    andreialecu edited #38962
  • 11:50
    andreialecu synchronize #38962
  • 11:39
    andreialecu synchronize #38962
  • 11:39
    andreialecu synchronize #38962
  • 11:38
    andreialecu synchronize #38962
  • 11:01
    andreialecu edited #38962
  • 11:01
    andreialecu opened #38962
  • 10:59
    andreialecu closed #38961
  • 10:58
    typescript-bot labeled #38961
  • 10:58
    andreialecu opened #38961
  • 10:57
    wangzhilongh opened #38960
  • 10:50
    andreialecu opened #38959
  • 06:07
    Hucy closed #38524
  • 05:20
    jhutchings1 ready_for_review #38939
  • 04:59
    imba-tjd edited #38822
  • 04:31
    typescript-bot synchronize #38917
  • 03:16
    yseymour closed #27413
A. Matías Quezada
@amatiasq
sorry for taking it to the extreme, I'm testing how far can typescript go ;)
Bruce Pascoe
@fatcerberus
Yeah there’s an issue about that - you can’t access protected props of another instance of yourself - it’s not sound in general
I'm trying to find the issue as it's hard to explain
Basically the gist is that (from the compiler's POV) you don't know if bar is some sister type to Child, so it's not safe to allow you to access the protected prop
Bruce Pascoe
@fatcerberus
I assume that's what you were trying to do?
A. Matías Quezada
@amatiasq
fair enough, I mean you should only be able to call that method from that class (or derivate) as this but I see why it works this way
A. Matías Quezada
@amatiasq
yeah but I was using the special this argument, not a random one
Bruce Pascoe
@fatcerberus
Ah yeah there was an issue about that I just saw a few minutes ago
Let me try to find it again
Oh wait no that has the same issue:
let c: C = new C();
let b: B = new B();
b.fooey.call(c);
c.go();  // oops, runtime error!
A. Matías Quezada
@amatiasq
yep, tricky
fair enough
Bruce Pascoe
@fatcerberus
If you have an instance of your own class, it's allowed. But not one of your base classes
A. Matías Quezada
@amatiasq
thanks for clarifying it, that is really helpful :D
Bruce Pascoe
@fatcerberus
n/p
Alexander Gutheil
@gutisAlex_gitlab
Hey, I have a Question! When I have two objects obj1 and obj2 and do obj1.name = obj2.name is obj1.name then referenced to obj2.name or is it a just set to it and I can work with it without touching obj2.name?
Bruce Pascoe
@fatcerberus
If it’s an object then it’s always by reference
string, number, boolean are by value
im assuming obj.name would be a string
So yeah they would be independent
However if you do obj1 = obj2 then it’s a reference
Alexander Gutheil
@gutisAlex_gitlab
ok thx so far and if I have smth like obj1.nestedObj = obj2.nestedObj?
should I do obj1.nestedObj = { ...obj2.nestedObj } ?
Jason Luboff
@JLuboff
If you don't want it to be a reference, than yes you can use the spread operator for a shallow copy. If obj2 contains further objects, than those will still be references
Keith Layne
@keithlayne
that will only copy one level deep, but if that's all you have, then it's fine
A bunch of libraries have deep cloning utilities
tieTYT
@tieTYT
export interface TwineSave {
  version: number;
  state: { history: TwineHistory[] };
}

type TwineHistory = TwineState | TwineState_200;
How do I say that history should be homogeneous?
I don't want to mixture of those types, the array should only be of one type
export interface TwineSave {
  version: number;
  state: { history: TwineHistory };
}

type TwineHistory = TwineState[] | TwineState_200[];
?
Bruce Pascoe
@fatcerberus
Yes, that’s right. If you just have UnionTypeAlias[] there’s no way to force that to be homogenous - you need to name the types individually
Well I guess you could make a mapped type that does it for you
type Homogenous<T> = T extends any ? T[] : never
Which works because conditional types distribute over unions
Gerrit Birkeland
@Gerrit0
But isn't a mapped type ^
Bruce Pascoe
@fatcerberus
Eh, close enough. It maps one type to another. I realized I used the wrong term after I posted it but can't edit on mobile
I confused it because a mapped type maps over properties of an object type, not members of a union
tieTYT
@tieTYT
thanks for the help
Eric Blade
@ericblade
i have kind of a dumb question. I have absolutely no TypeScript mentors other than "the internet as a whole", considering that i am unemployed, and my last employer didn't use TS .. Perhaps due to my (also limited) C# experience, I tend to prefer a syntax like Array<type> rather than type[] . . . . is there a general preference one way or the other in TypeScript?
Niles
@Validark
@ericblade It comes down to personal preference. I personally prefer Array<type> since I think it looks nicer. Especially for T extends Array<infer U> ? U : never versus T extends (infer U)[] ? U : never.
undermouse
@ruslanDeveloperGit
Hi guys. I'm looking for a pair to write something in TypeScipt and ElectronJS
Who's interested?
bsdis
@bsdis
Hi. When calling a rest function, i have to specify the type that is returned which could for example be a dictionary with 3 entries (2 strings and 1 number). That works great if the endpoint always has the same return type - but what if the endpoint changes number of output parameters, names and types sometimes? What should then be specified in typescript? (There is however one entry in the dictionary which is always there, and that shows what the endpoint returns.)
Bruce Pascoe
@fatcerberus
Do you know all the possible things that can be returned? If so you could use a discriminated union
The "one entry which is always there" lets TS narrow it
@bsdis