encore icon indicating copy to clipboard operation
encore copied to clipboard

Cannot use a simple third-party union type in typed API params

Open CodeWithOz opened this issue 6 months ago • 2 comments

Steps to reproduce:

  • create new encore project
  • install countries-list
  • import TCountryCode type from countries list: import { TCountryCode } from "countries-list"
  • use it as the type of a field in an encore endpoint param: api<{ country: TCountryCode }, void>(...).
  • run encore: encore run
Error:
error: object not found: TCountryCode
  --> /path/to/app.ts:12:10
   |
12 | import { TCountryCode } from "countries-list";
   |          ^^^^^^^^^^^^


error: unknown identifier
  --> /path/to/app.ts:24:29
   |
24 |   async (params: { country: TCountryCode }): Promise<{ success: boolean }> => {
   | 

Worth noting that the TCountryCode type is a very basic union type that's exported normally from the index.d.ts file. Surprising to say the least that this would raise an error with encore. Perhaps another case of incomplete typescript support, similar to what's happening in #1669 ?

CodeWithOz avatar May 26 '25 17:05 CodeWithOz

No, the actual type definition is here: https://github.com/annexare/Countries/blob/cc382a4045cc7ca1ecd4c479de402dee1ba28929/packages/countries/src/types.ts#L6

Which is a more complex definition using keyof typeof:

export type TCountryCode = keyof typeof countries

eandre avatar May 26 '25 17:05 eandre

@eandre I see! Thanks for clarifying. So does that mean it is indeed the same typescript support limitation that causes the problem in the linked issue?

CodeWithOz avatar May 26 '25 17:05 CodeWithOz

@CodeWithOz Could you try upgrading to latest encore version and see if that resolves the issue? we recently have made some improvements to the type resolve that would cause this error. The latest version is v1.48.10

fredr avatar Jul 18 '25 09:07 fredr