popeindustries / lit-html-server

Render lit-html templates on the server as Node.js streams
MIT License
265 stars 12 forks source link

Type Declarations like lit-html? #41

Closed Grunet closed 5 years ago

Grunet commented 5 years ago

Is there any way to use lit-html-server in typescript and benefit from the intellisense, type checking, etc... that the typescript compiler can provide? It looks like the core lit-html project emits declaration files, but the source is already in typescript there.

I tried converting all of the lit-html-server source to typescript using the js-to-ts-converter package and was able to clean up most of the resulting compile errors without much understanding of what the code was doing around it, but there were a couple I wasn't so sure how to handle.

popeindustries commented 5 years ago

It’s unfortunate that TypeScript projects don’t understand importing JS libraries using TSDocs. Creating *.d.ts files should just be copying the TSDocs from the existing source. I think @AndersCan was working on this?

Grunet commented 5 years ago

I found a solution from #https://github.com/microsoft/TypeScript/issues/29056 by setting allowJS to true and maxNodeModuleJsDepth to 5 in my tsconfig, which seems to pull in the JSDocs correctly. It looks like that's just a workaround for #https://github.com/microsoft/TypeScript/issues/7546 though.

The one build error I'm getting with that now in my starter project is that the "html" function seems to be expecting a string array instead of a TemplateStringsArray.

image

It looks like the core lit-html project has this typed as a TemplateStringsArray, so maybe the doc just needs updating?

image

image

Not a big deal of course since I can just turn off the type checking for it