#Return type of exported function has or is using private name

10 messages · Page 1 of 1 (latest)

whole granite
#

Hi, im getting TS error code (4060) in the following playground example.

// @strict: true
// @target: ES2024
// @module: NodeNext
// @moduleResolution: NodeNext

// @filename: a.ts
export interface A {
    readonly prop: number
}

export function isInstance(v: unknown): v is A {
    return !!v && typeof v === "object" && "prop" in v;
}

export * as A from "./a.js"

// @filename: entry.ts
import { A } from "./a.js"

// using A as a type works as expected
function f(a: A): number {
  return a.prop;
}

// using A as a namespace also works as expected
console.log(A.isInstance(13));

Workbench Repro

Could someone please help me in understanding why the error happens?
Interestingly, if I try this in my codebase and run tsc, the code does what i want: VSCode complains about the same error, but doesn't let me "ts-ignore" it

lusty yewBOT
#

@whole granite Here's a shortened URL of your playground link! You can remove the full link from your message.

helenetr#0

Preview:```ts
// @strict: true
// @target: ES2024
// @module: NodeNext
// @moduleResolution: NodeNext

// @filename: a.ts
export interface A {
readonly prop: number
}

export function isInstance(v: unknown): v is A {
return !!v && typeof v === "object" && "prop" in v;
...```

shadow drum
#

are you trying to barrel export from the same file?

whole granite
#

yeah, exactly. I want users to be able to just type "A" in their IDE and either:

  • use A as a type directly
  • or get autocompletion for things that are under the "A" namespace
shadow drum
#

the A namespace being the A interface and the isInstance function?

whole granite
#

correct ("A" namespace will of course also include the interface "A" again, but it should also be possible to just write "A" when you just want the type)

#

the thing i dont get is: it works (i tried this pattern in a rather large codebase) -> but i dont know how to get rid of this error. From my POV, it looks like TSC is complaining about something that doesnt actually have "consequence" 🤨

shadow drum
whole granite
#

😃

shadow drum
#

well this is terrifying and i have no idea how to approach this