• @folkrav
    link
    85
    edit-2
    1 year ago

    deleted by creator

    • @PoopMonster
      link
      431 year ago

      Just as irritating as seeing people use linters only to have a lot of files with @ts-ignore all over the place… Like why even bother?

      • @[email protected]
        link
        fedilink
        3
        edit-2
        1 year ago

        I’ve literally just put ts-ignore in many many files. The reason was legacy stuff, we had the ts check off (which blocks a merge if it failed), because there were just too many files that would need fixing. We thought about the best way to add the check so that new files have to have proper types, while having an easy way to slowly fix old ones.

        We decided to go with ts-ignore for every file and a lint warning for the same line. So you see it in each file if it needs to be fixed, but you’re not going blind for red ts errors everywhere or don’t have the check at all.

    • fusio
      link
      121 year ago

      using any is actually much worse than using TS, because you’re basically telling the compiler “don’t help me here”… at least with JS the IDE is gonna help you… :/

      • @folkrav
        link
        3
        edit-2
        1 year ago

        deleted by creator

    • @[email protected]
      link
      fedilink
      31 year ago

      I don’t follow, stamping every function with : any lets you merge the branch and deploy it… trying to properly type everything extends the initial migration time likely to a level where management just says no.

      • @folkrav
        link
        7
        edit-2
        1 year ago

        deleted by creator

        • @[email protected]
          link
          fedilink
          4
          edit-2
          1 year ago

          I disagree that you’re worse off (the core of my comment was that even a shitty migration encourages better practices)… but I wasn’t super familiar with TS hinting - using ts-ignore would be preferable.

          Personally, I mostly work in PHP and we use a similar system. Strict typing is default off so we’ve slowly propagated declare(strict_types=1); to enable compile and runtime checking on a per file basis.

  • @alokir
    link
    551 year ago

    It’s a good way to get started, and then incrementally type as much as you can, preferably everything.

    Later on, or if you start a new project with TypeScript, it’s a good idea to turn on noImplicitAny and only allow explicit any in very specific framework level code, unit tests or if you interface with an untyped framework.

    The hassle really pays off later.

    • fusio
      link
      211 year ago

      this is terrible advise - you should be using unknown. using any you’re basically disabling TS and will be under the false assumption that your code is ok while it’s most likely missing a lot of runtime checks

    • @[email protected]
      link
      fedilink
      -11
      edit-2
      1 year ago

      But if your code ever integrates with javascript you still need any everywhere so it’s pretty pointless

      • @9point6
        link
        13
        edit-2
        1 year ago

        Not true, in the absolute worst case, unknown is what you should be reaching for, but it’s pretty rare that you can’t create some kind of type to interface with JS if it’s not already got types. You can even use jsdoc comments as type hints in the JS too if you own that code.

        My not particularly hot hot-take: There’s basically no legitimate use case for any apart from “I don’t have time to type all this now, because I’m converting a massive project from JS to TS”

        • @[email protected]
          link
          fedilink
          English
          51 year ago

          There are some cases where any must be used instead of unknown but they usually involve generic constraints and seem more like a bug than intended behavior

          • @9point6
            link
            21 year ago

            Ah you’re right there, and I also agree, that feels more like a bug than by design

      • @alokir
        link
        41 year ago

        Not necessarily, depending on your situation you can type the JS code yourself.

        If the team making the JS code were using jsdoc then the Typescript compiler can recognize the comments and use it for type checking.

        In some instances the compiler can infer types from JS code to do some basic validation.

        Even if the external JS code is recognized as any, your own code that’s using it still has types, so it’s better than nothing.

  • @ABC123itsEASY
    link
    11 year ago

    Nah this isn’t the way, friend. Instead of adding a bunch of useless anys all over the place, start typing in one part of the application and exclude the rest using a path pattern. Or simply allow .js and only change the extension for files you’ve typed. Doing this is just wasting time and creating false assurances of type safety.
    It’s not that hard to define correct, meaningful types. Often vscode already has implicitly determined them for you; just mouseover the variable.

  • Max-P
    link
    fedilink
    -31 year ago

    I wish I did that, at this point my TypeScript template errors are as long as C++'s ._.

    • FibreChips
      link
      331 year ago

      Ah yes, node, the JS runtime that very famously doesn’t ever get used with typescript

    • @alokir
      link
      181 year ago

      Typescript is a language, Node is a platform and framework. You can use Typescript in your Node project, they’re not mutually exclusive.

      The way I see it Typescript is more popular than ever, almost all (popular) libraries come with types and every job offer I get they use Typescript.

      And with good reason, our team recently took over a small Javascript app and there are tons of bugs that would never have existed if they were using Typescript. Things like they refactored something but missed to update a reference, or misspelled a variable name, failed to provide a required parameter to a funcrion, referenced a field that existed in another config object etc.

      • @kautau
        link
        5
        edit-2
        1 year ago

        And thankfully we might be getting to a point where TS no longer needs to exist: https://github.com/tc39/proposal-type-annotations

        It’s about time JS gave us the ability to be strict on types, and have that as part of the interpreter as opposed to needing to transpile TS with the overhead involved

    • @[email protected]
      link
      fedilink
      51 year ago

      Managing a node project is like juggling twelve barrels full of monkeys… and those monkeys have rabies. Trying to keep all your dependencies in line is insane.

      • @[email protected]
        link
        fedilink
        21 year ago

        It is absolutely insane to me that people rag on the Python packing ecosystem when TypeScript exists. Sure, Python’s not perfect (Rust and Go seem better, from the small amount I’ve dabbled with them), but way easier and more stable than any TS project I’ve worked on.