TS version – 5.2.2
My VSCode typescript can’t see exports of types nested in namespaces. ORM Prisma library have the generated types, which exported from namespace.
That’s how the usage is shown in docs:
import { Prisma } from '@prisma/client'
const userEmail: Prisma.UserSelect = {
...
}
But I don’t have any suggestions for UserSelect
at namespace Prisma
(it is generated in file, but exported by export type
), which I import from the same path ‘@prisma/client’. If I try to write Prisma.UserSelect
I get an error, saying that there is no UserSelect
in namespace Prisma
.
Everything which is exported by export type
isn’t exporting. I made a simple code to show the problem:
// fileA
export namespace bar {
export const a = 2; // just a variable
export type b = string | undefined; // trying to export type (doesn't work)
export let c: b; // using non-exporting type on variable
}
// fileB
import { bar } from "./fileA";
bar.a // 2 exported without an "export type", so everything is working
//let foo: bar.b // Error, no 'b' in namespace 'bar'
// Next lines shows a possible soltuion, but I don't want to use that method to solve the problem..
let foo: typeof bar.c // The same type as "bar.b", but it works (next line shows)
foo = 0; // TS Error, because "type b = string | undefined" (== typeof c) and 0 - "number" type
Using variable type nested into namespace cause VSCode to give bad infomation about type (it just shows “bar.b”, not “string | undefined” as an type a
, which bar.b
is). Is there any suggestions why it doesn’t work and how I have to export types from namespace?