consola icon indicating copy to clipboard operation
consola copied to clipboard

Types from `consola` and `consola/core` are not the same

Open tobiasdiez opened this issue 8 months ago • 2 comments

Environment

  • Operating System: Windows_NT
  • Node Version: v23.9.0
  • Nuxt Version: 3.14.1592
  • CLI Version: 3.16.0
  • Nitro Version: 2.10.4
  • Package Manager: [email protected]

Reproduction

import { useLogger } from '@nuxt/kit'
import type { ConsolaInstance } from 'consola/core'

export const logger: ConsolaInstance = useLogger('nuxt:storybook')

Describe the bug

The above code yields

src/logger.ts(7,14): error TS2719: Type 'import("D:/Programming/nuxt-storybook/node_modules/.pnpm/[email protected]/node_modules/cons…  
│   Type 'ConsolaInstance' is not assignable to type 'Consola'.
│     The types of 'options.reporters' are incompatible between these types.
│       Type 'import("D:/Programming/nuxt-storybook/node_modules/.pnpm/[email protected]/node_modules/consola/dist/core").ConsolaReport…  
│         Type 'import("D:/Programming/nuxt-storybook/node_modules/.pnpm/[email protected]/node_modules/consola/dist/core").ConsolaRepo…  
│           Types of property 'log' are incompatible.
│             Type '(logObj: import("D:/Programming/nuxt-storybook/node_modules/.pnpm/[email protected]/node_modules/consola/dist/core"…  
│               Types of parameters 'ctx' and 'ctx' are incompatible.
│                 Type '{ options: import("D:/Programming/nuxt-storybook/node_modules/.pnpm/[email protected]/node_modules/consola/dist…  
│                   The types of 'options.prompt' are incompatible between these types.
│                     Type '(<_ = any, __ = any, T extends PromptOptions = import("D:/Programming/nuxt-storybook/node_modules/.pnpm…
│                       Type '<_ = any, __ = any, T extends PromptOptions = import("D:/Programming/nuxt-storybook/node_modules/.pnp…  
│                         Type 'Promise<inferPromptReturnType<T> | inferPromptCancalReturnType<T>>' is not assignable to type 'Prom…  
│                           Type 'inferPromptReturnType<T> | inferPromptCancalReturnType<T>' is not assignable to type 'inferPrompt…  
│                             Type 'inferPromptCancalReturnType<T>' is not assignable to type 'inferPromptReturnType<T> | inferProm…  
│                               Type 'string | boolean | SelectOption | (string | SelectOption)[] | unique symbol | null | undefine…  
│                                 Type 'undefined' is not assignable to type 'inferPromptReturnType<T> | inferPromptCancalReturnTyp…  

while using import type { ConsolaInstance } from 'consola' (without /core) works perfectly fine.

Additional context

Context: https://github.com/nuxt-modules/storybook/pull/880 https://github.com/nuxt-modules/storybook/issues/870#issuecomment-2779879069 https://github.com/nuxt-modules/tailwindcss/pull/972

Logs


tobiasdiez avatar Apr 06 '25 09:04 tobiasdiez

why you need to import consolaInstancece from /core subpath not main subpath?

pi0 avatar Apr 06 '25 09:04 pi0

There is no particular reason. But I would say the exported types should be compatible, or there should be only one 'correct' way.

tobiasdiez avatar Apr 10 '25 11:04 tobiasdiez