Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

development guide of TypeScript #630

Open
aqzhyi opened this issue Jan 14, 2020 · 2 comments
Open

development guide of TypeScript #630

aqzhyi opened this issue Jan 14, 2020 · 2 comments
Assignees
Labels

Comments

@aqzhyi
Copy link
Contributor

aqzhyi commented Jan 14, 2020

Hi, I just looking for a development guide for TypeScript.

Or maybe just an interface LineClient or LineAction got export is enough for me.

The reason is bottender now got have interfaces of Action, Client, Event and Props etc. It's wonderful.

With these interfaces, I can say const SayHi: Action<Client, Event>, which with argument interfaces context.sendText and props?.next and etc.

But the problem is Action<Client, Event> interface has no context.sendFlex, and seems LineClient has no export by bottender. Therefore I can not tell VSCode Action<LineClient, LineEvent>.

Currently, my workaround is

export const QueryWar3rStreams= async (
 context: LineContext,
  props: Props<Client, LineEvent> & { ownPropsAsString: string },
) => {
  console.info(props.ownPropsAsString)

  return props?.next
}

The workaround is working fine, but it will get the next problem on import { text } from 'bottender'

export default async function App(context: LineContext): Promise<unknown> {
  return router([text(/^[$$](直播|live)/i, QueryWar3rStreams as any)])
}
[ts]   Types of parameters 'context' and 'context' are incompatible.
[ts]     Type 'Context<LineClient, LineEvent>' is missing the following properties from type 'LineContext': _customAccessToken, _isReplied, _shouldBatch, _replyMessages, and 61 more.

What do you think?

@chentsulin chentsulin added the doc label Jan 17, 2020
@aqzhyi
Copy link
Contributor Author

aqzhyi commented Jan 19, 2020

I am now using simple interfaces.

export type WithGroupProps<OwnMatchProps = {}> = {
  match?: { groups?: Partial<OwnMatchProps> }
}

export type LineAction<OwnProps = {}> = (
  context: LineContext,
  props: Props<Client, LineEvent> & OwnProps,
) => Promise<Action<Client, LineEvent> | undefined | void>

// it can return props.next
expectType<LineAction>(async (context, props) => {
  console.assert(context.sendFlex.call)
  return props.next
})

// it can have OwnProps
expectType<
  LineAction<{
    ownProp1: { nestProp1: string }
    ownProp2: { nestProp2: string }
  }>
>(async (context, props) => {
  console.assert(props.ownProp1.nestProp1)
  console.assert(props.ownProp2.nestProp2)
})

// it can use with WithGroupProps
expectType<
  LineAction<
    {
      ownProp1: { nestProp1: string }
      ownProp2: { nestProp2: string }
    } & WithGroupProps<{
      command: string
    }>
  >
>(async (context, props) => {
  console.assert(props.match?.groups?.command)
  console.assert(props.ownProp1.nestProp1)
  console.assert(props.ownProp2.nestProp2)
})

FYI thanks

@dcsan
Copy link

dcsan commented Jul 22, 2020

@hilezir are you still proceeding with this? I hit a requirement failure when trying to move to typescript, written up in #847

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants