Re:TypeScript support in Electron
by AgentME on Friday June 02, 2017 @05:13PM
(#14473346)
Does Typescript still require you to have definitions for every library in order to use the library? One thing I love about Flow is that it doesn't have that requirement. You can start using a new library, and later on if you find that type safety in that library's exports would be useful, then you can look for or write definitions then. You're not blocked from adopting the library. I find for many of my dependencies that I use in a few spots it's not really important for me to have definitions for.
[ Parent
| on HN ]
I don't think that Typescript ever did require that? AFAIK, it has always been possible to just declare the variable as "any" type and use it as if it were untyped.
I thought I remembered using require statements and getting errors from the typescript compiler that it couldn't find the (typescript definitions for the) file.
Can confirm. This has been my experience.
technically you do need to define at the top level, but no, not in a practical sense:
declare var $: any;
$( "element" ).compiler.leaves.you.alone
You can always add a quick and dirty definition like:
declare module 'themodule' { var mock: any; export default mock; }
But unless the lib doesn't propagate through your code at all, it pays of to give it proper typings.
Re:TypeScript support in Electron
by mattmanser on Friday June 02, 2017 @08:28PM
(#14474213)
In the rare cases we find a library that doesn't have a typescript definition, we just do:
declare var Thing : any;
In a global definition file.Pro tip. We've got a lot of mixed js and ts at the moment and when you're really lazy you can take advantage of how every object is a dictionary in js and just do something like `window["notification"]` instead of window.notification, which resolves to an 'any' type in ts.
Obviously you should try and minimise that usage, but it's a useful trick to know.