Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: remove the word 'duck typing' in structural-type-system section. #3319

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from

Conversation

mohammednumaan
Copy link

@mohammednumaan mohammednumaan commented Feb 1, 2025

In the Structural Type System section, the documentation states that TypeScript’s type checking can be referred to as duck typing because it compares the shape of values. However, this is incorrect due to the following reasons:

  • duck typing compares types based on behavior.
  • structural typing compares types based on their structure (or) the members they contain.

This PR resolves the above issue.

@mohammednumaan
Copy link
Author

@jakebailey hey, if you don't mind, can you review this PR? Thanks!

@jakebailey
Copy link
Member

I can't say I agree with the change; TS has interfaces, function properties, etc, which to me very much qualify.

@mohammednumaan
Copy link
Author

mohammednumaan commented Feb 26, 2025

I can't say I agree with the change; TS has interfaces, function properties, etc, which to me very much qualify.

@jakebailey yes, but at its core ts is structurally typed code, not duck typed.

One of TypeScript’s core principles is that type checking focuses on the shape that values have. This is sometimes called “duck typing” or “structural typing”.

Imo, in this context, or duck typing shouldn't be included.

@orta
Copy link
Contributor

orta commented Feb 26, 2025

I thought the gains in comparing to duck typing were valuable originally, but I found myself agreeing with the PR in general after reading the duck typing wikipedia page and c2

JavaScript is duck-typing in the sense that its "try it and see", but I've never heard a JS person refer to JS as a duck-typed language (and that is who the doc is aimed at) so dropping it as unnecessary jargon is probably a win.

Personally, I'd go a bit harder on the structural typing reference:

One of TypeScript's core principles is that type checking focuses on the shape that values have. This is commonly called "structural typing".

@mohammednumaan
Copy link
Author

mohammednumaan commented Feb 26, 2025

@orta yep. as far as i know, there is another important distinction:

  • in duck typing, the type compatibility is determined at runtime.
  • in structural typing, the type compatibility is determined at compile time.

and since ts at its core is structurally typed, imo its better to remove the duck typing to not cause any confusion 🤔.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants