3 ms·
> So, is there an ELI5 for the difference between structural typing and duck typing? While similar, structural typing is seen statically (think compile time),
by randomdata 2y ago
> So, is there an ELI5 for the difference between structural typing and duck typing?
While similar, structural typing is seen statically (think compile time), duck typing is seen dynamically (think run time).
- moritzwarhier 2y agoThanks, this makes sense, TS type narrowing only works with information known at compile-time (even when using runtime constructs for type narrowing). So I will go on to imagine duck-typing as the classic JS way where functions started with often pretty extensive runtime checks of their parameter values. I guess this also means that duck-typing is inherently tied to checking primitive types and/or object structures, return values etc at runtime.