Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 03:23
    whitneyit opened #44715
  • 03:16
    Kingwl synchronize #43370
  • 01:23
    rbuckton synchronize #43370
  • 01:07
    Jack-Works edited #42359
  • Jun 23 23:49
    RyanCavanaugh closed #14226
  • Jun 23 23:49
    RyanCavanaugh unlabeled #14226
  • Jun 23 23:49
    RyanCavanaugh unlabeled #14226
  • Jun 23 23:49
    RyanCavanaugh labeled #14226
  • Jun 23 23:48
    RyanCavanaugh closed #15159
  • Jun 23 23:47
    RyanCavanaugh labeled #15159
  • Jun 23 23:47
    RyanCavanaugh unlabeled #15159
  • Jun 23 23:44
    RyanCavanaugh labeled #20821
  • Jun 23 23:44
    RyanCavanaugh unlabeled #20821
  • Jun 23 23:44
    RyanCavanaugh edited #20821
  • Jun 23 23:44
    RyanCavanaugh unassigned #20821
  • Jun 23 23:44
    RyanCavanaugh labeled #20821
  • Jun 23 23:44
    RyanCavanaugh milestoned #20821
  • Jun 23 23:43
    RyanCavanaugh closed #21424
  • Jun 23 23:31
    RyanCavanaugh closed #14219
  • Jun 23 23:29
    RyanCavanaugh unlabeled #14219
Blind4Basics
@Blind4Basics
(note: I'm fairly new to all of this... Don't hesitate to state the obivous!)
webstrand
@webstrand
ReferenceError is definitely a runtime error
Path2D isn't from a library then?
Blind4Basics
@Blind4Basics
webstrand
@webstrand
ah, you're trying to run this in node, not the browser?
Blind4Basics
@Blind4Basics
yep
webstrand
@webstrand
the issue is that node doesn't implement those APIs
(it doesn't implement most web apis)
Blind4Basics
@Blind4Basics
fuck, I was worried about that
webstrand
@webstrand
there might be a polyfill...
Blind4Basics
@Blind4Basics
polyfill?
impossible to load/import that thing?
(the web api)
webstrand
@webstrand
there's a polyfill, but it doesn't implement Path2D: Automattic/node-canvas#1116
why are you trying to do canvas stuff from node?
Blind4Basics
@Blind4Basics
because the class was appealing... x)
'didn't realize I was trying to walk throuh a wall... :/
webstrand
@webstrand
the thing is, node doesn, by default, have anywhere to render the canvas to
a browser has a window to render into.
Blind4Basics
@Blind4Basics
well, I guess I can build the same without the extension
webstrand
@webstrand
You could use electron, and render it in the provided browser window
Blind4Basics
@Blind4Basics
yeah, I'll build a canvas in an html page at some point. I'm just not there yet in the dev
mm, right
so, installing electron, configuring the project, then the class will be available?
webstrand
@webstrand
inside the electron context, the class will be available.
Blind4Basics
@Blind4Basics
ok, thx a lot. I believe I know what I'll do this evening... x)
cheers
Archimedes Trajano
@trajano

Hi I was wondering if I can refactor a generic typing to a type so I don't have to repeat the bounds. Here's my code.

  export interface FormChangeEvent<T> extends FormEvent {
    name: 'change';
    params: {
      metas: Record<string, unknown>;
      name: string;
      value: unknown;
      /**
       * Original values before the change.
       */
      values: T;
    };
  }
  export interface FormSubmitEvent<T> extends FormEvent {
    name: 'submit';
    params: {
      values: T;
    };
  }

  export declare function Form<T extends Record<string,unknown>>(props: {
    formData: T,
    schema: Record<string, unknown>,
    uiSchema: Record<string, unknown>,
    widgets: Record<string, (props:any) => JSX.Element>,
    HeadingComponent: (props:any) => JSX.Element,
    SubmitButton: (props:any) => JSX.Element,
    onChange: (event: FormChangeEvent<T>) => Promise<void>
    onSubmit: (event: FormSubmitEvent<T>) => Promise<void>
  }): JSX.Element;

as you can see in Form I have the bounds, I realize I have to put the same bounds on the events, but I was wondering if I can avoid retyping extends Record<string,unknown>

I know I can do this... but it is tedious

  export interface FormSubmitEvent<T extends Record<string,unknown>> extends FormEvent {
    name: 'submit';
    params: {
      values: T;
    };
  }
Bruce Pascoe
@fatcerberus
type RSU = Record<string, unknown>;
T extends RSU
Archimedes Trajano
@trajano
@fatcerberus is there a way to do it such that type FormData = <? extends Record<String, Unknown> so I can do FormChangeEvent<FormData>
AnyhowStep
@AnyhowStep
There's no macro or anything like it
Bruce Pascoe
@fatcerberus
No you can't do that
Just think of a generic as a type-level function, you have to specify the full parameter list of all function definitions. Same goes for type parameters
The closest you can get is
type FormData = Record<string, unknown>;
interface FormChangeEvent<T extends FormData> {
    /* ... */
}
Which honestly isn't that much more typing than what you propose
Archimedes Trajano
@trajano
Yup thanks for the info
But actually what you have is more understandable.
Especially since there's going to be different contexts for Record<string, unknown>
type BaseFormData = Record<string,unknown>;
  type JsonSchema = Record<string,unknown>;
  type Uichema = Record<string,unknown>;
that way when we expand the other two we just change it in one spot rather than searching for Record<string,unknown> and try to decipher the context.
Archimedes Trajano
@trajano
Hi. What do you call that thing where you can have a type that is a combination of two different types like in my case I have a name:"submit" and name:"change" in my interface and have typescript figure out which one to use based on an if check? I have something that isn't working the way I expected it but I can't find the term in the Typescript handbook
Mind you I could've done it correctly and it's because I'm on Javascript and just relying on // @ts-check
Bruce Pascoe
@fatcerberus
You’re probably thinking of discriminated unions
Bruce Pascoe
@fatcerberus
Just remember that because TS is structurally typed it’s going to treat all your Record<string, unknown> aliases as the same exact type
So if you’re hoping for added type safety that way you’re going to be disappointed
bsdis
@bsdis
Hi, if i do like this: event_type = ["tap" as "tap", "pan" as "pan", "move" as "move"]; what is the meaning of as then?
AnyhowStep
@AnyhowStep

They're called type assertions.
I prefer to call them "trust me, compiler, I know what type this is" expressions.

The compiler might see the value "tap" and infer either string as its type, or "tap".
Both inferences are correct.
However, you might want to force the type of "tap" to something specific.

So, you use as "tap" or as string.

bsdis
@bsdis
aha isee
thanks for the answer :)
Bruce Pascoe
@fatcerberus
If you’re trying to force an object literal to have all its contents as their literal types ("tap" as "tap") then it’s safer just to do as const on the whole object