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

TypeScript Rollout Tier 5 - Toast #349

Merged
merged 7 commits into from
Jan 6, 2025

Conversation

kikuomax
Copy link
Collaborator

@kikuomax kikuomax commented Jan 2, 2025

Related issues:

Proposed Changes

  • Migration of toast and related docs
    • packages/buefy-next/rollup.config.mjs, and packages/buefy-next/src/utils/vue-augmentation.ts may cause conflicts after merging other PRs in this tier.

- Rewrites `Toast` in TypeScript:
  - Defines a new type `ToastProps` that represents the props type of
    `Toast`. `ToastOpenParams` extends this (see below).

  Trivial changes:
  - Adds `lang="ts"` to the script section
  - Wraps the entire component definition with `defineComponent` API

- Rewrites `component/toast/index.js` in TypeScript:
  - Defines a new type `ToastOpenParams` that represents the parameters
    type for `open`. `ToastOpenParams` accepts `VNode`(s) as `message`
    in addition to `string`(s).
  - Defines a new type `ToastProgrammaticInstance` that has the minimal
    interface of a programmatically opened `Toast` instance

  The following changes might not be trivial:
  - Renders `VNode` and an array of `VNode`(s) or `string`(s) through
    the slot. It used to render an array through the slot, but a single
    `VNode` also had to be rendered in the slot, otherwise `v-html`
    binding would try to stringify it.
  - Removes `params.parent` because it no longer has any effect
  - Replaces the `merge` helper function with spread syntax to provide
    the default value for `position`

  Trivial changes:
  - Replaces the extension: `.js` → `.ts`
  - Gives minimal types
- Rewrites `Toast.spec.js` in TypeScript:
  - Replaces `jest` API calls with those of `vi`: `fn`, `uesFakeTimers`,
    `useRealTimers`, and `advanceTimersByTime`
  - Replaces the extension: `.js` → `.ts`
  - Imports necessary functions and object from `vitest`
  - Gives minimal types

  Replaces the spec snapshot `Toast.spec.js.snap` with the one generated
  by `vitest` → `Toast.spec.ts.snap`.
Binds `$buefy.toast` to `ToastProgrammatic`.
`rollup.config.mjs` removes "toast" from `JS_COMPONENTS`.
Rewrites example components in `pages/components/toast` in TypeScript.
Most of the changes are straightforward.

In `examples/ExSimple.vue`:
- Extraction of the type of a programmatically opened toast instance
  might look tricky (`ToastProgrammaticInstance`)

In `Toast.vue`:
- Separates the code snippet to an external file
  `outside-vue-instance.js` because dev build might treat it as the
  actual code and end up with an unresolved module error

Here is a TypeScript migration tip:
- Explicitly import and register components so that they are type
  checked. No type-checking is performed for globally registered
  components.
@kikuomax kikuomax requested a review from wesdevpro January 2, 2025 07:58
wesdevpro
wesdevpro previously approved these changes Jan 4, 2025
@wesdevpro wesdevpro self-requested a review January 6, 2025 01:09
@kikuomax kikuomax merged commit f982964 into ntohq:dev Jan 6, 2025
18 checks passed
@kikuomax kikuomax deleted the ts-rollout-tier-5-toast branch January 6, 2025 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants