uuid: - value: 1420a8f0-0482-4fa6-86ec-876d84c27255 langcode: - value: en type: - target_id: daily_email target_type: node_type target_uuid: 8bde1f2f-eef9-4f2d-ae9c-96921f8193d7 revision_timestamp: - value: '2025-05-11T09:00:32+00:00' revision_uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 revision_log: { } status: - value: true uid: - target_type: user target_uuid: b8966985-d4b2-42a7-a319-2e94ccfbb849 title: - value: | Why I prefer types created: - value: '2023-09-20T00:00:00+00:00' changed: - value: '2025-05-11T09:00:32+00:00' promote: - value: false sticky: - value: false default_langcode: - value: true revision_translation_affected: - value: true path: - alias: /daily/2023/09/20/why-i-prefer-types langcode: en body: - value: |

Whether it's PHP or JavaScript/TypeScript, I prefer type declarations in my code.

As well as benefits like auto-completion in your IDE or text editor and being able to more effectively statically analyse the code, to me, the code is more readable and easier to understand with the types included.

It's more to read, but I can do so easily and immediately know what a function expects as function arguments and what it will return.

Here's the code from my previous email on types from a few days ago, with and without the types declared:

add(...numbers) {
        // ...
      }

      subtract(...numbers) {
        // ...
      }

      add(...numbers: number[]): number {
        // ...
      }

      subtract(...numbers: number[]): number {
        // ...
      }
      

Without types, I can infer what the function accepts and returns, but that's based on my assumption, which could be incorrect.

What if numbers was an array of strings of numbers - e.g. ['one', 'two', 'three'] - and what if instead of returning the result, it stored it in state to return from a different method like equals() or calculate()?

With the type declarations included, I don't need to presume, infer or make best guesses.

It's clear from just reading the code.

format: full_html processed: |

Whether it's PHP or JavaScript/TypeScript, I prefer type declarations in my code.

As well as benefits like auto-completion in your IDE or text editor and being able to more effectively statically analyse the code, to me, the code is more readable and easier to understand with the types included.

It's more to read, but I can do so easily and immediately know what a function expects as function arguments and what it will return.

Here's the code from my previous email on types from a few days ago, with and without the types declared:

add(...numbers) {
        // ...
      }

      subtract(...numbers) {
        // ...
      }

      add(...numbers: number[]): number {
        // ...
      }

      subtract(...numbers: number[]): number {
        // ...
      }
      

Without types, I can infer what the function accepts and returns, but that's based on my assumption, which could be incorrect.

What if numbers was an array of strings of numbers - e.g. ['one', 'two', 'three'] - and what if instead of returning the result, it stored it in state to return from a different method like equals() or calculate()?

With the type declarations included, I don't need to presume, infer or make best guesses.

It's clear from just reading the code.

summary: null field_daily_email_cta: { }