Skip to content

PoC for #36165 'inherit' keyword - #64811

Draft
Tadhg McDonald-Jensen (tadhgmister) wants to merge 2 commits into
microsoft:mainfrom
tadhgmister:inherit-PoC
Draft

Tadhg McDonald-Jensen (tadhgmister) wants to merge 2 commits into
microsoft:mainfrom
tadhgmister:inherit-PoC

Conversation

@tadhgmister

@tadhgmister Tadhg McDonald-Jensen (tadhgmister) commented Oct 14, 2026 •

Copy link
Copy Markdown

Adds the example inherit type alias with generics into the es5.d.ts lib and adds some logic to getTypeFromTypeAliasReference in checker.go that auto fills the generics when omitted to the 'inherit' type alias.

This PoC has several limitations with the way it was implemented:

  • being put in the standard library declarations, it gets offered at all type positions even though they are totally invalid
  • the definition only supports up to 4 arguments before a rest argument, doing foo(a:1, b:2, c:3, d:4, e:5, ...rest: inherit) fails saying a string literal error message does not extend an array type.
  • if a local type called inherit is defined, it can get generic arguments specified for it even though it doesn't actually correspond to the expected type (this is because it is only matched by symbol name)
  • when inherit is used somewhere it is not expected to be used it gives the error message that it expects 2-4 type arguments instead of saying "it isn't legal to use it there" which would be far more helpful.
  • it is possible to manually specify type arguments to inherit which is probably not super useful at production level.
  • the constraints on the generics are bypassed because the part of the code that would validate the generic constraints is not modified. As such several cases that should produce errors that simply resolve to never instead.

Several correct and expected behaviours are recorded into a test case which passes with this implementation.

AI usage disclosure:

  • the 138 lines of go code was written by AI, I mainly guided how to structure the functions.
  • the test code was composed by AI from many disorganized examples I wrote to test the feature.

Fixes #36165

@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 14, 2026
@tadhgmister

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Adds the example inherit type alias with generics into the es5.d.ts lib
and adds some logic to getTypeFromTypeAliasReference in checker.go
that auto fills the generics when omitted to the 'inherit' type alias.

Also has updated tests to see the correct behaviour of the intended feature.

AI usage disclosure:
- the go code was mostly written by AI and should not be considered production quality.
- the test code was composed by AI from many examples I wrote to test the feature.
Now properly identifies getters and setters instead of trying to treat the return/first arg
of the field which if the field is not a function type would go to 'never'

Also removed the explicit generic case from the test suite, isn't really something we necessarily want to support

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inherit keyword as shorthand to refer to super class fields and methods.

1 participant