Skip to content

bug: missing export of DatetimeHighlightStyle #27353

Closed

Description

@aparajita

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

Although the source does export DatetimeHighlightStyle, the built package does not, which results in a TS error when trying to import it.

Expected Behavior

DatetimeHighlightStyle should be exported in the built package.

Steps to Reproduce

  1. Open any project.
  2. Enter the following:
import { DatetimeHighlightStyle } from '@ionic/core'
  1. TypeScript will complain that @ionic/core does not export that name.

Code Reproduction URL

https://stackblitz.com/edit/xkg3uz?file=src/main.ts

Ionic Info

Ionic:

   Ionic CLI : 7.1.1 (/Users/aparajita/Developer/projects/clients/willsub/apps-monorepo/node_modules/.pnpm/@[email protected]/node_modules/@ionic/cli)

Capacitor:

   Capacitor CLI      : 4.8.0
   @capacitor/android : 4.8.0 (/Users/aparajita/Developer/projects/clients/willsub/apps-monorepo/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@capacitor/android)
   @capacitor/core    : 4.8.0 (/Users/aparajita/Developer/projects/clients/willsub/apps-monorepo/node_modules/.pnpm/@[email protected]/node_modules/@capacitor/core)
   @capacitor/ios     : 4.8.0 (/Users/aparajita/Developer/projects/clients/willsub/apps-monorepo/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@capacitor/ios)

Utility:

   cordova-res : not installed globally
   native-run  : not installed globally

System:

   NodeJS : v20.0.0 (/Users/aparajita/Library/pnpm/nodejs/20.0.0/bin/node)
   npm    : 9.6.4
   OS     : macOS Unknown

Additional Information

The relevant line in the built package is @ionic/core/types/components.d.ts, lines 18 and 54, which sure enough are missing the relevant name:

import { DatetimeChangeEventDetail, DatetimeHighlight, DatetimeHighlightCallback, DatetimePresentation, TitleSelectedDatesFormatter } from "./components/datetime/datetime-interface";

export { DatetimeChangeEventDetail, DatetimeHighlight, DatetimeHighlightCallback, DatetimePresentation, TitleSelectedDatesFormatter } from "./components/datetime/datetime-interface";

Activity

  1. added
    package: core
    type: bug
    on May 3, 2023
  2. sean-perkins commented on May 3, 2023

    @sean-perkins
    Contributor

    Hello @aparajita thanks for this issue! Can you share your intended usage requiring the DatetimeHighlightStyle type?

    To bind to highlightedDates, consumers should need DatetimeHighlight or DatetimeHighlightCallback. Are you requiring the type for the return type of DatetimeHighlightCallback?

  3. self-assigned this
    on May 3, 2023
  4. aparajita commented on May 3, 2023

    @aparajita
    Author

    Hey @sean-perkins, first of all, since DatetimeHighlight is defined as:

    export type DatetimeHighlight = {
      date: string;
    } & DatetimeHighlightStyle;

    not exporting DatetimeHighlightStyle does not allow us to set the style separately from the date in a type-safe manner. I'm not quite sure what the rationale is behind that, if indeed it was a conscious choice.

    Here's the relevant portions of my code:

      const kDateHighlights: Record<string, DatetimeHighlightStyle> = {
        available: {
          textColor: 'var(--ion-color-dark-contrast)',
          backgroundColor: 'var(--color-available-job)',
        },
        assigned: {
          textColor: 'var(--ion-color-dark-contrast)',
          backgroundColor: 'var(--color-assigned-job)',
        },
        pto: {
          textColor: 'var(--ion-color-dark-contrast)',
          backgroundColor: 'var(--color-pto)',
        },
      }
    
      function getDateHighlight(item: ListItem): DatetimeHighlightStyle {
        if (isAvailableJob(item)) {
          return kDateHighlights.available
        } else if (isAssignedJob(item)) {
          return kDateHighlights.assigned
        } else {
          return kDateHighlights.pto
        }
      }
    
      // Not exactly my code, but the general idea
      const highlightedDates = computed((): DatetimeHighlight[] => {
        const highlights: DatetimeHighlight[] = []
    
        for (const item of items) {
          // Without DatetimeHighlightStyle being defined, TS sees the object
          // parameter as `any`.
          highlights.push({
            date: item.date,
            ...getDateHighlight(item)
          })
        }
      })
  5. sean-perkins commented on May 3, 2023

    @sean-perkins
    Contributor

    @aparajita thanks for the code snippet, that makes sense!

    Stencil v3 includes a feature that automatically exports types assigned to a @Prop. Prior to this, Ionic Framework had to manually export all individual types. The downside to this, is that types that are consumed in those automatically exported types, are not additionally exported. That is the case here, where we missed exporting this lower-level type for developers.

    I will open #27360 for review.

  6. aparajita commented on May 3, 2023

    @aparajita
    Author

    Thanks @sean-perkins. I am able to work around it for now by declaring the type myself.

  7. removed their assignment
    on May 3, 2023
  8. added a commit that references this issue on May 4, 2023
    a37cdb1
  9. ionitron-bot commented on Jun 3, 2023

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  10. locked and limited conversation to collaborators on Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: coretype: bug

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions