Don't put your types in .d.ts files

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ก.ย. 2024

ความคิดเห็น • 291

  • @mattpocockuk
    @mattpocockuk  ปีที่แล้ว +39

    New audio setup arrived today - thanks for bearing with me during my failed Shotgun Mic experiment.

    • @herrpez
      @herrpez ปีที่แล้ว

      You pre-empted me and my commenting, you rascal! 😉
      Tbh though, whatever you've got going could work just fine as long as you eliminate the echo. That is to say, sound treating the room.

    • @mattpocockuk
      @mattpocockuk  ปีที่แล้ว +2

      @@herrpez If you're on Twitter, you'll be able to see the latest no-echo setup:
      twitter.com/mattpocockuk/status/1677624336285421569

    • @herrpez
      @herrpez ปีที่แล้ว

      @@mattpocockuk Sounds a lot better, and is no doubt a great deal easier than modifying the environment to suit the shotgun mic. 🙂

  • @TomasDohnal10
    @TomasDohnal10 ปีที่แล้ว +159

    I think folks do it cuz:
    1) The ".d" part of the filename makes it seems like it's where you should define types or something
    2) When you open any library "d.ts" file and you'll see that it's a file full of type definitions, one can get the impression that "d.ts" files are simply files where you define types you wanna use across your project
    (not saying that's right, just describing the impression i had had)

    • @mattpocockuk
      @mattpocockuk  ปีที่แล้ว +32

      Absolutely! I was surprised how many people got that impression.

    • @DisturbedNeo
      @DisturbedNeo ปีที่แล้ว +28

      I think the real reason is that it makes the types global with no imports necessary.
      Devs love globals, no matter how bad it makes the code smell.

    • @evol777
      @evol777 ปีที่แล้ว +9

      That's why I generally don't like 90% of the web devs I've encountered: they assume lots of stuff and usually think others are in the wrong, not them.
      Web devs are the forever wanna be devs, not putting enough work to understand their flaws and wanting others to bend to their flawed necessities.
      And I'm a web dev.

    • @Tommy-nn8xf
      @Tommy-nn8xf ปีที่แล้ว +1

      That is exactly me. I put all my types in .d.ts file, maybe I should stop doing that from now on. Should I just put them in a .ts file then?

    • @Tommy-nn8xf
      @Tommy-nn8xf ปีที่แล้ว +2

      @@MAXHASS-ph5ib Thanks for the suggestion!

  • @Remeroska
    @Remeroska ปีที่แล้ว +9

    I have an answer to your question: Why do people use them?
    I can answer anecdotally with my experience: because ts docs are a mess, and you didn't yet made an explaination video about it.
    2 takeaways: - ts docs should be rewritten from scratch - you are a rare gem, thanks for existing ❤

  • @Sagarclips
    @Sagarclips หลายเดือนก่อน

    clear, consise, crisp - You have awesome voice Matt!

  • @ikechukwucharles2314
    @ikechukwucharles2314 ปีที่แล้ว

    Well said Matt. When writing typescript code is usually have a directory "types" in which files that add my own types to the global namespace using declare global ...
    Good one 👍

  • @dvillegaspro
    @dvillegaspro ปีที่แล้ว +2

    Thanks for the revelation, Matt. I think I do this because types feel like such a specific feature of a codebase to me that it doesn't make sense for type declarations to be modular inherently. It made more sense in my head for them to be global; if TS doesn't end up in the bundle anyway, why should I care about the import statements? That's just how I thought about it, but never thought that it could be an issue.

  • @ElendiarDev
    @ElendiarDev 6 หลายเดือนก่อน

    Thanks, that exactly that info i want.
    I wondered why I shouldn’t store all my types and interfaces in d.ts, because it looked convenient - I don’t have to import them.
    But I suspected there was a catch somewhere...

  • @hrax
    @hrax หลายเดือนก่อน

    Just found this video as I am learning TS. Well, time to refactor my code, while it is still fresh. :D

  • @naraksama3903
    @naraksama3903 ปีที่แล้ว +3

    Putting my internal types into a global.d.ts file caused me a lot of headaches to actually get it to work and then realize that this approach was completely stupid. Not only because Typescript interprets two different types of declaration files (one with imports and one without), but also because it's very cumbersome since you have to re-type all the used internal classes because of the type-value difference.
    I learned that you should not use declaration files if the compiler does not complain about missing types from external modules or unknown imported file types it cannot read.

  • @typeguard
    @typeguard ปีที่แล้ว +1

    Found this out the hard way a while ago. Now I only use .d.ts files to declare certain modules I need to have globally available. For example, if I'm using SCSS modules, Typescript normally doesn't know or understand what they are so I declare them in my types.d.ts as
    declare module "*.module.scss" {
    const content: { [className: string]: string };
    export default content;
    }
    I suppose this is what it was meant for

  • @ward7576
    @ward7576 ปีที่แล้ว

    This explanation pretty much put you on main part of normal distribution where on the left side there's a noob and other side senior, saying "it works, don't care".

  • @hypergraphic
    @hypergraphic ปีที่แล้ว +1

    That's very helpful to know! Something else I've wondered, is should we put centralize the types, or have them distributed around the codebase. At work, we have a types folder with multiple files for each kind of category like auth.ts, billing.ts, etc. Is that an antipattern?

    • @mattpocockuk
      @mattpocockuk  ปีที่แล้ว +2

      Here you go!
      www.totaltypescript.com/where-to-put-your-types-in-application-code

    • @hypergraphic
      @hypergraphic ปีที่แล้ว +1

      @@mattpocockuk thanks!

  • @AlexanderCerutti
    @AlexanderCerutti ปีที่แล้ว +2

    Hi Matt, thanks for this! Very interesting. About skipLibCheck, I thought it was about all the typings, not just custom ones. But why disabling it? I mean, wouldn't it be better to have it disabled ("false") so TS warn you are making code-smell?
    Would it be perhaps be better to have a tsconfig.build.json file that turns it true while on development it is turned to false?
    I'm used to always create two tsconfig files, one for build and one for development. What's your suggestion here? Do you agree with this way of making ts projects? Thanks!

    • @mattpocockuk
      @mattpocockuk  ปีที่แล้ว +1

      You definitely want the same rules in your tsconfig in dev and production. Much easier maintenance and keeps things more secure in the long run.

    • @AlexanderCerutti
      @AlexanderCerutti ปีที่แล้ว +1

      @@mattpocockuk I make tsconfig.json to extend tsconfig.build.json, so what's really important stands in production file while things like "paths" stays in the dev

  • @waqaskhandev
    @waqaskhandev ปีที่แล้ว

    I was using it the right as you explained but any way it was good to know that I can make that mistake.

  • @DS-rq3gq
    @DS-rq3gq ปีที่แล้ว +1

    I used to do exactly this until I found out you can't put enums in .d.ts files. That's when I learned I was doing it wrong

  • @AntonPenqe
    @AntonPenqe ปีที่แล้ว

    I use .d.ts to declare some project specific types that I want to use everywhere in the project. That way they got into global scope so I don't need to import them in every single module that uses them. I also use namespaces, so different parts don't clash with each other. What's wrong with that?...

  • @hsul-git
    @hsul-git ปีที่แล้ว

    And why not keep types in the component itself when they are not reuseable?

  • @ExZeMIP
    @ExZeMIP ปีที่แล้ว

    I've never seen anyone using a .d.ts file using for types used in the actual project, just JavaScript libraries

  • @marceloprado2035
    @marceloprado2035 ปีที่แล้ว

    great content!

  • @Netherlands031
    @Netherlands031 ปีที่แล้ว +1

    So when should you use it - specifically when you have a .js with types?

    • @mattpocockuk
      @mattpocockuk  ปีที่แล้ว +3

      1. When you need to type some JavaScript
      2. When you want to make alterations to a global type, like in this article: www.totaltypescript.com/how-to-properly-type-window

  • @thekwoka4707
    @thekwoka4707 ปีที่แล้ว

    Can you do a video on why packages that ship with types, should include the declaration maps and source ts files in the package? It's very annoying not having `go to definition` work.

  • @Raul-si7bn
    @Raul-si7bn ปีที่แล้ว

    I have a related question that maybe somebody have faced before :
    If i create a `customTypes.ts` file, where I create and export some interfaces/types, and i put that file inside the folder where I have my `main.ts` file (where I write my code), How could I exclude that file/folder from the compilation?
    I'd like that the compiler do not create a `customTypes.js` when compiling.
    I tried to create a ` "exclude":["customTypes.ts"] ` in my `tsconfig.json`. , but since the file contains "export" declarations , the compiler walks through that file anyway.
    Do you have any standar solution, or a way to really exclude a file with import/export statements ?

  • @geraldaburto7712
    @geraldaburto7712 7 หลายเดือนก่อน

    What is wrong is to use the `export` key inside the types.d.ts file, right?

  • @nithingowda1060
    @nithingowda1060 ปีที่แล้ว

    I learnt this the hardway... haha

  • @XavierGoncalves89
    @XavierGoncalves89 ปีที่แล้ว

    I use .d.ts files to add type declarations for regular js dependencies that do not export types, is this wrong?

    • @mattpocockuk
      @mattpocockuk  ปีที่แล้ว +1

      Absolutely fine.

    • @XavierGoncalves89
      @XavierGoncalves89 ปีที่แล้ว

      @@mattpocockuk Thanks, another question: is there a way to bypass that file when I ctrl+click on the module import, and send me to the node_modules?

  • @LivvieLynn
    @LivvieLynn ปีที่แล้ว

    Can you declare global types outside of the types.d.ts file? I know you can export and import individual .d.ts files throughout a project but I'd like to better organize global types.

    • @mattpocockuk
      @mattpocockuk  ปีที่แล้ว +2

      declare global {
      interface MyGlobal {}
      }

  • @AnthonyPaulT
    @AnthonyPaulT ปีที่แล้ว +1

    after this video, i still don't understand what it's for

  • @ricardorng
    @ricardorng ปีที่แล้ว +1

    this happends because programmers don't know bases...

  • @PieterWigboldus
    @PieterWigboldus 7 หลายเดือนก่อน

    I think you have to reevaluate your sentence.
    That you dont do it when you write Typescript.
    But for JavaScript, you can do it.
    If you generate JavaScript from your Typescript code, or just writing JavaScript itself.
    you have a prejudice that everyone writes Typescript.
    Maybe it is your preference, but not for everybody.
    At the end, if you write Typescript or JavaScript, your production code is JavaScript (your application and npm package), with our without d.ts files.
    I think you only prefer to write Typescript, and dont want to write the d.ts itself by hand.

  • @renato360a
    @renato360a ปีที่แล้ว

    my No. 1 tip for any programming: don't do things you don't understand!

  • @GregRippetoe
    @GregRippetoe 7 หลายเดือนก่อน

    So there's no real reason to not put your types in .d.ts files apart from personal preference

  • @sael40
    @sael40 ปีที่แล้ว

    Why would I want runtime features (1:38) in my *types* files anyways? They're for types.
    I used to prefer types.d.ts exactly because of this - it only allows adding actual types, not utility functions but ESPECIALLY enums (which generates runtime code) which I absolutely despise

    • @mattpocockuk
      @mattpocockuk  ปีที่แล้ว +1

      skipLibCheck, though

    • @sael40
      @sael40 ปีที่แล้ว

      ​@@mattpocockuk yeah - that and global scope is enough for me to keep away from them 👍
      awesome video btw, as always

  • @shadowplay1211
    @shadowplay1211 ปีที่แล้ว +49

    I prefer separating types into different files inside a "types" folder that contain types for specific things (like database types in one file, utility types in other file and some app stuff in 3rd file), I don't like the approach of putting every single type into 1 file bc especially in large applications we end up with a huge and hard to maintain types file. Also, I put types into types files only if I have to use them somewhere else, otherwise I would just define a type right in the file that will use that type

    • @HCforLife1
      @HCforLife1 ปีที่แล้ว +6

      I think all depends on the scope of the project and it's nature. If it's big one with hundreds of PR's and thousands types defined having a giant single file would be ridiculous 😂 in my experience the best is a mix. If you have some types u use Everywhere - use them in global scope. If you have types you use only where you defined it or use them somewhere else where you import it - use them within the file. If you have complex use case where some interfaces are shared, some are used separately - create one file if that benefit the clarity. Also worth to discuss these as you go with your teammates to make sure that you all following the same patterns and that you all agree. But this actually should be a part of Code Review and initial phase of a project

    • @markbutterworth9598
      @markbutterworth9598 ปีที่แล้ว

      I do the same and for the first time I disagree with Matt on this one. If you put the types in a file co-located with the items using it (sometimes to solve circular references) and don't make it a definition file then you will now have an empty module output.
      I usually put the types in the same file but sometimes they need to be separated out for readability of the code it's typing for the other Devs in the team.
      I do agree there should never be actual code in a .d.ts file but then doing that had never even occurred to me.

    • @gunarcom
      @gunarcom ปีที่แล้ว

      Yup, I type stuff coming from APIs in d.ts files because they are global and are passed around through components. Seems like the correct way to do it so I am not having to redefine types every time I use them.

  • @code-island
    @code-island ปีที่แล้ว +50

    Hi Matt, keep this content up, I really love improving my typescript skills with you

  • @twothreeoneoneseventwoonefour5
    @twothreeoneoneseventwoonefour5 ปีที่แล้ว +78

    I use .d.ts to augment some types and interfaces of the external libraries.
    Example: there is a leaflet map library, and there are a bunch of plugins that are written in pure js, but they add to the library's inbuilt features. So to make typescript happy, I declare those types there.

    • @mattpocockuk
      @mattpocockuk  ปีที่แล้ว +25

      Yep - great idea.

    • @dvillegaspro
      @dvillegaspro ปีที่แล้ว +1

      Nice, I hadn't thought of doing this!

  • @BjornBrasse
    @BjornBrasse ปีที่แล้ว +4

    At 1:20 Let me show you exactly why they're so bad... But a straight up answer never comes (only indirectly)... So I think I understand, but the explanatation doesn't go into why declaring types globally is a bad idea. And why can packages use them for sure, but you shouldn't as module declaration files... Still unclear to me. 😊

  • @Zagoorland
    @Zagoorland ปีที่แล้ว +5

    I thought that d.ts was just naming convention for type related files and a lot of my dev friends also, lol…

  • @guilhermeferreirabr
    @guilhermeferreirabr ปีที่แล้ว +1

    So basically roughly half of the devs do not know what (or why) they are doing 😂Proper training and standards should be mandatory in our field ...

  • @ShotgunAFlyboy
    @ShotgunAFlyboy ปีที่แล้ว +5

    I used to write .d.ts files for ambient type suggestions via jsdoc before we took the time to swap to typescript's actual runtimes. It was a big project and it took a while to have the time to do the migration.

  • @samuelgunter
    @samuelgunter ปีที่แล้ว +1

    so if you wanted to make a package that was just a type definition to publish on npm, for example an AnyStringWithAutocomplete (that weird "| (string & {})" or something like that, you just have a .ts file instead of a .d.ts file?

  • @hamodeyDooba
    @hamodeyDooba ปีที่แล้ว +2

    i have to like before watching 🎉
    enough for me to see you publishing new content

  • @gosnooky
    @gosnooky ปีที่แล้ว +3

    All my projects have an index.d.ts in the project root where I augment libraries, like adding properties to the express req object, for typing process.env and adding semantic alises like type IsoDate = string or type UnixTimestamp = number.

    • @KurtLippert
      @KurtLippert ปีที่แล้ว

      I do this as well. I thought that was the use case for them. Is there an alternative?

  • @yega3k
    @yega3k ปีที่แล้ว +3

    I’ve been using TS because of ReactNative for years but it is only now that I’m realizing how much separate TS knowledge I need. I’m learning so much from your channel. Thank you the breakdowns!

  • @ragtop63
    @ragtop63 ปีที่แล้ว +1

    I mean, we are talking about a superset of features (because Typescript really isn’t a language) that was designed to make a scripting language do something it wasn’t designed to do. And the bandage keeps getting bigger and bigger.

  • @riendlyf
    @riendlyf 2 หลายเดือนก่อน

    PLEASE someone, can you create a video on HOW TO USE script CORRECTLY ?

  • @miervaldis42
    @miervaldis42 5 หลายเดือนก่อน

    I agree with you but then, I was wondering why npm suggests you to create a `.d.ts` file when it could have just told you to have types files ?
    N.B. : I am currently creating a React npm package and I just saw the npm message...

  • @eldbudd
    @eldbudd ปีที่แล้ว +2

    A huge smile spread on my face when i read the title of this video.
    About a year and a half ago i started my first frontend dev job, and on my very first task, on the very first week, i stumbled upon our app's huge usage of the .d.ts files. I tried asking several of my peers what is this ".d.ts" file, and nobody knew, one assumed that the "d" stands for "deprecated" (to which i replied in a question - "so why did you declare new types in a new .d.ts file just two weeks ago?").
    So i did a bit of investigation and soon enough i understood the depth of the antipattern that is spread all over.
    You see, i came from Python, and in Python, as Python is, it is extremely easy to make a huge mess and chaotic code, because no typing is required. So i was very sensitive to this issue.
    So at the end of this first week, and actually up until today, because this thing is like cancer, my crusade is to get rid of all our .d.ts files.
    Good luck to me.

  • @JordanICM
    @JordanICM 4 หลายเดือนก่อน

    I still dont understand the issue. I use d.ts files to make my types global so I don't have to import them into every file. What if every time I wanted to use "let" or "const", I had to import it? That would get annoying. So for certain other common fundamental types in my app, I put them in a d.ts file. Is that blasphemy?

  • @martonvalentin7386
    @martonvalentin7386 ปีที่แล้ว

    But if you put your types without "export" keyword into .d.ts files, tsc fails compiling. (Cannot find name "...") Am I missing something ?

  • @Alexander-by4uv
    @Alexander-by4uv ปีที่แล้ว

    Bad technology where people have to struggle with the question where their types go to ;-) Don't understand me wrong, TypeScript is the best thing which could happen to JS. But JS itself is horror and deserves to be forbidden :P

  • @doc8527
    @doc8527 ปีที่แล้ว

    After seeing tons of garbage typescript definition file all over the place from different projects time to time, where you have to constantly jump between different files to check out and correct the typescript. Similar to when you have a big CSS file or multiple CSS files where you constantly have to hop over to check out a specific class style.
    For 99% of the times and non library development, if there is no hard guideline for the typescript definition across the team, I simply put typescript definition on the top of the same file that is using the typescript if it's not going to be shared anywhere.
    No import, no export, less typescript confliction during the review, people change it on demand, scope well, move out of scope on demand, no premature "typescript optimization”, works the best.
    Big file issue? It's always case by case.
    Big file can be simple if the code flow is clean, small file can be complex if there are tons of unnecessary nested abstractions everywhere.
    People will thank me later if they don't need to jump between files to figure out a simple logic.

  • @echobucket
    @echobucket ปีที่แล้ว

    I feel like this is the TypeScript docs's fault. I remember trying to read the docs about .d.ts files and not understanding the use cases for them. The docs do not make this clear.

  • @jonhobbssmith
    @jonhobbssmith ปีที่แล้ว

    I'm confused here. At one point you say "that's what declaration files are for, putting things in the global scope". Thrn uoubgononnto say "never put types in the global scope".
    So, why? And what are you supposed to put in declaration files ifnit's.notnthe types you eant to share?
    If you have types that are used throuout your projectnthen why eould you want to be importing them in every file? And why are you trying to put runtime code in your type declaration files anyway?

  • @heinzerbrew
    @heinzerbrew ปีที่แล้ว

    How about a video on why 40% of the people do this wrong. Is it bad documentation? Are the profession books teaching this wrong? Did everyone just learn it from some random youtuber?

  • @Hemigoblin
    @Hemigoblin ปีที่แล้ว

    TypeScript is the last gasp of OOP for real-world programming. You can skew OOP or FP, ya gotta pick one.

  • @peachesfruitella
    @peachesfruitella ปีที่แล้ว

    whats interesting is why people use .d.ts in the first place .. as a FE dev we always just used .ts for interfaces ... but the internet kind of suggested otherwise. If it seemed like convention - people will follow. But why did we follow this guide to begin with?

  • @thinkingdev102
    @thinkingdev102 ปีที่แล้ว

    I use it for declaring types for our private js packages published by our organisation where they didn't bother to use typescript. 🤬

  • @OmkarBhoir07
    @OmkarBhoir07 ปีที่แล้ว

    How to handle the npm lib which doesn't support TS. That's the reason i disabled the lib type check in config.

  • @noelsoong777
    @noelsoong777 6 หลายเดือนก่อน

    I hate how fastify forces me to make d.ts files and use declaration merging for their interfaces. I spend weeks to setup the tsconfig so my monorepo packages work when being used as a dependency.

  • @ThePizzabrothersGaming
    @ThePizzabrothersGaming ปีที่แล้ว

    I hate .d.ts files because any time you jump to definition it actually jumps to the types. great, i know the types of this function that i have no idea what kt does..

  • @alexmachin1785
    @alexmachin1785 ปีที่แล้ว

    When i started at my new job i saw this .d.ts file nonsense and well continued the pattern, now i regret my decision 😅 volate your damn types or wirst case have a types folecto share types easily.

  • @NoelSoong
    @NoelSoong 6 หลายเดือนก่อน

    I hate how fastify is forcing me to use d.ts files when configuring for it in a more complex file structure like a monorepo is hell.

  • @learner8084
    @learner8084 ปีที่แล้ว

    Thanks. I've not known what's the .d.ts for previously. Now I know.

  • @AngusMcIntyre
    @AngusMcIntyre ปีที่แล้ว

    Classic case of devs thinking they are smart. Keep it simple, folks.

  • @GT-tj1qg
    @GT-tj1qg ปีที่แล้ว

    Why would anyone put all their variable declarations in a separate file anyway? What a stupid thing.

  • @antonarbus
    @antonarbus ปีที่แล้ว

    I’m running to fix my code before my tech manager watched this video

  • @duetwithme766
    @duetwithme766 ปีที่แล้ว

    File based organization of code is terrible period. Time to get rid of it and replace it with something more meaningful

  • @mateuszgajo9731
    @mateuszgajo9731 6 หลายเดือนก่อน

    Another problem you can run into, is that you can import non existing types to d.ts.

  • @modernkennnern
    @modernkennnern ปีที่แล้ว

    I've seen them of course, but I never understood what they did, so I never used them.
    Yay me, I guess

  • @ya4dang1
    @ya4dang1 ปีที่แล้ว

    So define types in .d.ts files for the sole purpose of not to manually import them else where is a bad idea?

  • @victorlongon
    @victorlongon ปีที่แล้ว

    I only use d.ts files to declare env variables or global things

  • @jonobrien8848
    @jonobrien8848 ปีที่แล้ว

    in other news, opinions make coding hard. News at 11.

  • @andreyokhrimenko2271
    @andreyokhrimenko2271 ปีที่แล้ว +1

    Thanks for the information, but I haven't seen the use of .d.ts files in any tutorial project other than declaring types and interfaces. However, if you create a types.d.ts file in the root of the project, you can use types and interfaces without importing them, but just by specifying types (interfaces), which in my opinion is very convenient.

  • @ndukachukz8067
    @ndukachukz8067 ปีที่แล้ว

    I only use them for my types and interfaces never had a module there

  • @Linuxdirk
    @Linuxdirk ปีที่แล้ว

    My types go right before the variable, where they belong.

  • @matttamal8332
    @matttamal8332 ปีที่แล้ว +1

    Hello, you're awesome. Great content dude!

  • @michaelharrington5860
    @michaelharrington5860 ปีที่แล้ว

    I wish I had 50% of your knowledge

  • @zuzukouzina-original
    @zuzukouzina-original 9 หลายเดือนก่อน

    So we need to use .d.ts like .h files for c/c++ code? 😳

  • @georgethenewbie
    @georgethenewbie 8 หลายเดือนก่อน

    Hi @mattpocockuk - I watched the video more than once and I'm confused between the title of it and its content. Can I use an env.d.ts global file in my Astro app for example to declare a type that I know for a fact I'll use throughout my codebase? Is this not recommended?

    • @mattpocockuk
      @mattpocockuk  8 หลายเดือนก่อน

      Globals are just a bit iffy - but I suppose a global type is basically fine.

  • @LetalisLatrodectus
    @LetalisLatrodectus 2 หลายเดือนก่อน

    If your large code base has js files that are typed with .d.ts files then surely you want skipLibCheck to be false correct?

  • @mhadi-dev
    @mhadi-dev ปีที่แล้ว

    This is what a successful clickbait really means

  • @boomknuffelaar
    @boomknuffelaar 8 หลายเดือนก่อน

    I hate how the .d.ts files are often used in Express apps. The request object is given to middleware and the type of its data property is often defined using a .d.ts file. But all of the properties have to marked as possibly null since that's how the request object starts. And then every single middleware function has to type-check that property again for type safety.

    • @mattpocockuk
      @mattpocockuk  8 หลายเดือนก่อน

      Yeah it's not ideal. trpc does a much better job here.

  • @chris94kennedy
    @chris94kennedy ปีที่แล้ว +1

    Thanks Matt as per usual. The Typescript Don.

  • @pixiedev
    @pixiedev ปีที่แล้ว

    thanks to save my time buddy 👍🏻.

  • @lacherolachero9409
    @lacherolachero9409 ปีที่แล้ว

    that's not completely true, if you export something from a .d.ts file it behaves like a module and not make your types globally accessible

  • @farahrayis5928
    @farahrayis5928 ปีที่แล้ว

    I think I have read about this in the docs...

  • @workflowinmind
    @workflowinmind ปีที่แล้ว

    Matt, I'm not kidding please write a ts book, I'll buy it instantly

    • @mattpocockuk
      @mattpocockuk  ปีที่แล้ว

      Might be something in the works here...

  • @NutchapolSal
    @NutchapolSal ปีที่แล้ว +1

    i think a better explanation is that it is for compiled ts code that has become js, not for us to write directly
    so you can have the actual runnable code, and the types for developers to use

    • @yega3k
      @yega3k ปีที่แล้ว

      This is what I got from the included link.

  • @SakuraDev
    @SakuraDev ปีที่แล้ว +4

    Hi, I didn't know that .d.ts files push the types in the global scope. Really love that feature. Love the video as well 🙏

    • @rubendacostaesilva8442
      @rubendacostaesilva8442 ปีที่แล้ว

      It's a cool feature, but you will have to be careful naming your types, specially if you're using React, or any other library or framework, because you could be naming a type with a name that already being used by that library/framework, and if you're not paying attention, you could end up choosing the wrong type.

  • @arcanernz
    @arcanernz 10 หลายเดือนก่อน

    I put mine in a .t.ts file for just types

  • @geraldaburto7712
    @geraldaburto7712 7 หลายเดือนก่อน

    I got confused, It is OK to put my global types inside the types.d.ts file or not?

    • @mattpocockuk
      @mattpocockuk  7 หลายเดือนก่อน

      That pattern is sort of fine, but I'd prefer my types imported and exported.

  • @nephis_2006
    @nephis_2006 ปีที่แล้ว

    Ty, my coworkers will listen to me now

  • @weirdwordcombo
    @weirdwordcombo ปีที่แล้ว +1

    I sometimes use global types for automatic declaration merging because I need to extend types that I share with my git submodule(s). This means i can share types with my submodule, but also extend these types with project specific stuff. I don't use .d.ts files for this, instead I use "declare global" in normal module files. Before watching your vid, I would have said it doesn't make a difference, but with your skipLibCheck advice, it does actually.

  • @i007c
    @i007c ปีที่แล้ว

    well this is just a bad language design

  • @danieltkach2330
    @danieltkach2330 ปีที่แล้ว

    C# is an actual typed language 🙂

  • @kahdeksan
    @kahdeksan ปีที่แล้ว

    i always have a .d.ts file for my glsl files:
    declare module "*.glsl" {
    const value: string
    export default value
    }
    is this the correct way to do this? or should i use plain .ts?

  • @tcortega
    @tcortega ปีที่แล้ว

    i like your channel

  • @SamInNZ
    @SamInNZ ปีที่แล้ว

    Would you advise against using d.ts to store global type helpers?

    • @mattpocockuk
      @mattpocockuk  ปีที่แล้ว

      No - globals is what .d.ts files are for!

  • @Cahnisama
    @Cahnisama ปีที่แล้ว

    Pls bb, let me put just the type there.

  • @wattsfield1889
    @wattsfield1889 ปีที่แล้ว

    Interesting! Is this somehow connected to "import type"?