Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 10:37
    uraway edited #42418
  • 09:33
    uraway edited #42418
  • 09:30
    uraway opened #42418
  • 09:07
    SimonSimCity opened #42417
  • 07:36
    typescript-bot synchronize #42366
  • 07:03
    armanio123 synchronize #42356
  • 06:53
    github-actions[bot] synchronize #28460
  • 06:53
    github-actions[bot] synchronize #15575
  • 06:53
    github-actions[bot] synchronize #31641
  • 06:52

    github-actions[bot] on master

    Update package-lock.json (compare)

  • 05:26
    octogonz closed #42389
  • 04:42
    typescript-bot synchronize #42366
  • 02:41
    typescript-bot synchronize #42366
  • 02:32
    aminpaks synchronize #42141
  • 02:02
    weswigham synchronize #15575
  • 02:02
    weswigham synchronize #28460
  • 02:02
    weswigham synchronize #31641
  • 02:02

    weswigham on master

    Add missing unwrap call for theā€¦ (compare)

  • 02:02
    weswigham closed #42409
  • 02:02
    weswigham closed #42331
Julian Gonggrijp
@jgonggrijp
What else would this be, though?
And how did you come up with the idea to try that?
webstrand
@webstrand
not sure, I still don't understand where the types are going wrong.
Everything else looked fine, so I became suspicious of this

you can also do

processAnnotation(this: AnnotationView, model: Model, annotation: Model)

to "fix" the issue

but I'm not yet sure what the underlying cause is
ohryan
@orpheus
When migrating a react/js app to ts, do I remove babel-loader, babel.config.js, etc? In this article I'm reading it says to remove babel because conversion is now handled by the typescript loader.
webstrand
@webstrand
probably should follow the article. You can use typescript/react or typescript/babel/react, it just depends on how you configure your build system
ohryan
@orpheus
Ah I see, I misread. Thank you.
webstrand
@webstrand
@jgonggrijp Here's a simplified example playground
Julian Gonggrijp
@jgonggrijp
@webstrand Could you copy-paste the URL again? It seems to be missing the first N characters.
webstrand
@webstrand
oh sure
since bar.disposeClever("a") works outside of a method
I think your only fix is to add this: AnnotationView
to the method
I'm not sure why this isn't being propagated property, I'd almost accuse it of being a bug
Julian Gonggrijp
@jgonggrijp
@webstrand That's a great reduction, thanks!
What does the b!: number notation do, by the way?
webstrand
@webstrand
You might want to use that version of SubviewNames in your own code, since it doesn't use a mapped type
the ! says don't worry about initialization
Actually, you're probably better off using (this as AnnotationView) instead of changing the method's signature
Adding this: AnnotationView might make extending AnnotationView more frustrating, later.
Julian Gonggrijp
@jgonggrijp
Yeah that seems like it will be better in the face of inheritance.
How does your version of SubviewNames do the right thing? To my naieve eyes, it looks like it requires all keys of T to be number.
or rather, all properties.
webstrand
@webstrand
Oh you'll want to replace number with View<any>
Another way to solve your issue above is
    processAnnotation(model: Model, annotation: Model): void;
    processAnnotation(this: AnnotationView, model: Model, annotation: Model): void {
        ...
    }
using an overload to hide the this: AnnotationView and make it private to your implementation.

For SubviewNames:

type SubviewNames<T, U extends keyof T = keyof T> = U extends unknown ? T[U] extends View<any> ? U : never : never;

works for your example

Julian Gonggrijp
@jgonggrijp
Yeah I understand number is just a placeholder for View<any>, but even then it looks to me like it's requiring all properties of T to be of that type.
Also, what is the role of U extends unknown?
webstrand
@webstrand
The way it works is:
You use SubviewNames like SubviewNames<YourType> and never pass the second argument
The second argument U extends keyof T = keyof T exists solely to put keyof T into a generic argument so that we can distribute the union
U extends unknown ? ... distributes the keys and performs the T[U] extends View<any> ? U : never for each key in the union U individually
Here's another way to write it, without using the U extends keyof T = keyof T
type SubviewNames<T> = _SubviewNames<T, keyof T>
/** @private */
type _SubviewNames<T, U extends keyof T> = U extends unknown ? T[U] extends number ? U : never : never;
Julian Gonggrijp
@jgonggrijp
Ahhh that's clever. See @keithlayne , this demonstrates again that I have no intuition for distribution...
webstrand
@webstrand
I wish typescript distributed without a variable, then I could just do keyof T extends unknown. But no, for some strange reason, that doesn't work.
Julian Gonggrijp
@jgonggrijp
Well anyway, I'm immensely grateful for your help. I'll submit an issue to TS and credit you for the reduced testcase.
webstrand
@webstrand
Hope they find a bug! But likely as not there's a good reason for it to work the way it does, however frustrating.
Julian Gonggrijp
@jgonggrijp
TS has frustratingly many of those, in my opinion...
webstrand
@webstrand
yeah. I still like it a whole lot more than any of the alternatives, though (that preserve the javascript syntax, anyway)
Julian Gonggrijp
@jgonggrijp
Oh, and I'll post back here when there is a result.
Shanon Jackson
@ShanonJackson
@orpheus no you don't there's no need
babel can compile typescript files, aslong as you handle typechecking another way (Normally withhttps://www.npmjs.com/package/fork-ts-checker-webpack-plugin) as they can't type check
I would suggest using babel instead of ts-loader or ATL because it should be faster as it doesn't have to parse as much meta data as typescript compiler does
Typescript's compile process involves traversing the entire tree adding files to the "program" and then can compile the file.
Babels compile process ignores the entire tree and just processes the root file instantly.
Julian Gonggrijp
@jgonggrijp
@webstrand #42413
webstrand
@webstrand
thanks!
ohryan
@orpheus
@ShanonJackson Ok so if I understand it correctly, that fork-ts-checker does the type checking, but you still use ts-loader with transpileOnly: true? When would you use @babel/plugin-transform-typescript?
Shanon Jackson
@ShanonJackson
I don't use ts-loader or awesome-typescript-loader just babel with preset "preset-typescript"
Babel is just faster and gives more flexability; Given that you can get your typechecking through other means