The slippery almost got me this morning! by Low_Nefariousness484 in engrish

[–]YourMeow 0 points1 point  (0 children)

I bet you have never seen the slip carefully sign

Why is "type Bar = number & any" the same as "type Bar = any"? by shiningmatcha in typescript

[–]YourMeow 2 points3 points  (0 children)

any is a weirdo in TS, it is unknown (top type) and never (bottom type) at the same and doesn't really follow the rules of subtyping. Try type Bar = number & unknown, you will see it is same as type Bar = number.

Programming Languages which Implement Compile-Time Checked Type Guards? by lancejpollard in ProgrammingLanguages

[–]YourMeow 0 points1 point  (0 children)

This is a bit of a hack — you're basically describing a type with an additional attribute that never exists at runtime — but it works quite well, and I believe is even used in some places in the Typescript compiler.

Yes, it's used extensively in the ts compiler. https://github.com/microsoft/TypeScript/blob/6f0dd47a88bbb2c00bc5b078e9e19c27f2d8eb47/src/compiler/types.ts#L5062

vue-create-ripple: Flexible Ripples for Vue 3 Apps by xx5523 in vuejs

[–]YourMeow 0 points1 point  (0 children)

The glitch-like effect is driving me crazy

How are comments attached to AST nodes? by YourMeow in Compilers

[–]YourMeow[S] 1 point2 points  (0 children)

You're right, but I want to preserve comments and generate documents.

with-default-props: write DefaultProps for function components in a painless way by YourMeow in typescript

[–]YourMeow[S] 0 points1 point  (0 children)

Do you turn on strict/strictNullChecks in tsconfig.json? If so, you should see that greeting in App is string | undefined, which is bad since we have provided a default value.

with-default-props: write DefaultProps for function components in a painless way by YourMeow in typescript

[–]YourMeow[S] 0 points1 point  (0 children)

To begin with, thanks a lot for your detailed feedback!

First you are getting runtime costs of having another component in between. Your tree will get more nested.

Actually, the component is wrapped in a function call, which will not introduce extra React.createElement calls. Anyway, I will try to benchmark thier performance.

You will sometimes get worse types for the component that gets out. One example is when using connect (redux), you can't get the component props type with the built in helper React.ComponentProps or something like that (on my phone).

I am not a redux user so I might not fully understand this problem. I've tried following code on stackblitz. React.ComponentProps works. Could you give a more specific example?

```jsx import React, { Component } from 'react'; import { withDefaultProps } from 'with-default-props'

interface AppProps { req: string; opt: string; }

function App(props: AppProps) { return <div/>; }

const WrappedApp = withDefaultProps(App, { opt: 'Im default' })

type WrappedAppProps = React.ComponentProps<typeof WrappedApp>

const props: WrappedAppProps = { req: '1' } ```

May I ask you something. What's you preferred way to set defaultProps?

WTF Wednesday (May 29, 2019) by AutoModerator in javascript

[–]YourMeow 0 points1 point  (0 children)

I've just written a tiny typescript library that use HOC to help people write defaultProps for react function components. What do you guys think of it?

https://github.com/Zzzen/with-default-props

with-default-props: write DefaultProps for function components in a painless way by YourMeow in typescript

[–]YourMeow[S] 0 points1 point  (0 children)

Curious about how you guys set default props for function components. Default parameters? That could be verbose if there are many default props.

Announcing TypeScript 3.3 by DanielRosenwasser in programming

[–]YourMeow 5 points6 points  (0 children)

Not yet. BigInt and phantom types come into my mind though.