maierfelix/nvk

Typescript is broken?

Closed this issue · 6 comments

So I am currently working with nvk and would like to use it as its module (ie: nvk.VulkanWindow, not VulkanWindow.) I would do this by omitting the Object.assign(global, nvk) included in the examples. However when I do this typescript throws an error on every nvk.* I write. However when compiled it still works. Furthermore if I use the object assign then everything still works however I get no errors. Is there a reason for this and could you provide some incite as to why nvk works this way?

This essentially boils to how nvk is generated, in the nvk/generated/{version}/{platform}/index.d.ts - You'll see it declares all vulkan api stuff in a declare global { ... } block. That's why TS complains if you don't do Object.assign on the global. I do too feel that this is clunky and kinda not the TS way. I'd more prefer import { VulkanWindow } from 'nvk' than the current approach.

Will try to fiddle with it and see where it brings me, i believe there's a reason for this approach though.

Vulkan consists of hundreds of objects and functions, I expected users to not want to import every single thing, since you already have to write a lot of code in Vulkan.

@zeeshan595 might can add something here too, as he recently updated on how nvk gets imported in Typescript

I'm open for change proposals, as I'm not really a Typescript user

Something like this is what your looking for #37

Exactly like that :)

If you throw this file inside node_modules/nvk/ it should work properly. I tested it by creating a window and works fine for me
https://github.com/zeeshan595/nvk/blob/master/index.d.ts

image

should be fixed in v0.7.3