DEV Community

Discussion on: Vanilla TypeScript (gts)

Collapse
 
samuraiseoul profile image
Sophie The Lionhart

Getting a vanilla TS project going should be as simple as:

npm init
npm install typescript @types/node
npx tsc --init
Enter fullscreen mode Exit fullscreen mode

After that you need to decide which linter to use if any, among other tools and libraries, but that sets up a basic TS project for you. You still need to decide if you're gonna use webpack or babel or whatever, though TS can handle a lot of that for you too. Going through their configuration documentation will show a lot of cool things you can do with just the TS compiler.

Also I don't think you need to do <any>window in TS because there's no need to do window.whatever I do believe. Though without a code snippet perhaps I misunderstood you and am wrong.

Collapse
 
rfornal profile image
bob.ts

I'll look at that option; this article was something I came across ... perhaps I'll run this pattern on the next project I do. The article I found that generated this one was two years old and piqued my curiosity.

  1. Unfortunately, I didn't find this on a quick search.
  2. I did find something interesting I wanted to try out.

As to <any>window ... there is a specific need within my project (which will be made public soon, not yet).

Thanks for the "food for thought," awesome information!

Collapse
 
elarcis profile image
Elarcis • Edited

There is a way to extend the Window interface and declare the type of your globals so that you don't lose TS's help (using any should always be avoided):in a typings.d.ts file possibly at the root of your source folder, write something like that:

declare global {
  interface Window {
    myGlobal: string;
  }
}
Thread Thread
 
rfornal profile image
bob.ts

Elegant. I’ve gone through a few other things. I’ll try it out.