Today I Learned

Some TIL notes

2025

  • vite-plugin-validate-env

    validate environment variables at build or dev time

    January 3, 2025

    I sometimes put stringified JSON and has bunch of env variable keys. It’s hard to know when there’s an issue within the env value unless we really understand the whole env vars we define and where its used beneath the app.

    Astro v5 has env validator built in. t3-env lib also serves this purpose. It’s also possible to write custom validator and run it as custom script.

    I look for seamless validation on my vite app and glad that there’s a vite plugin for it: @julr/vite-plugin-validate-env. It runs on dev & build time only and support zod.

2024

2023

  • TypeScript: Function Overloads

    specify a function that can be called in different ways and multiple return type

    November 15, 2023

    We can define multiple function declarations to define different signatures (parameters/return types) and TypeScript will infer the right signature based on call arguments.

    Some gotchas:

    • Implementation should narrow types based on overload
    • Order matters: put most specific overloads first

    Use Cases:

    • Reusable functions with different types
    • Library functions mimicking overloads
    • Gradual typing - multiple signatures

    Example:

    // Overloads
    function getString(opts: { fallback: string }): string;
    function getString(opts: {}): string | undefined;
    
    // Implementation
    function getString(opts: {}): string | undefined {
      // ...
    }
    
    // Usage
    const str1 = getString({ fallback: 'hello' }); // string
    const str2 = getString({}); // string | undefined

    References: TypeScript Handbook




  • vite-plugin-checker

    Add type checking and linting support for vite

    September 5, 2023

    vite-plugin-checker preview

    I was looking for how to improve my vite react project by showing type-check or lint error like CRA’s error overlay. Then I found a plugin called vite-plugin-checker. The configuration is pretty straightforward.

    References: https://vite-plugin-checker.netlify.app/


  • Zod refine or superRefine check

    refine and superRefine check run after there's no invalid type error anymore in the base schema.

    July 28, 2023

    I sometimes got stuck when doing validations through refine or superRefine. Turns out refine and superRefine checking is run after there’s no more invalid type error on the base schema. It’s kinda expected but idk why is this not documented well.


  • FlutterShark

    How to Detect if an App is Built Using Flutter

    February 1, 2023

    [Android OS] FlutterShark able to detect and list down which app being installed in device are built using flutter. It will give these informations:

    • Flutter SDK version
    • Dart SDK version
    • Packages being used

2022

2021