Check order dependence with mutually-recursive non-unary generics
See original GitHub issueBug Report
Adding an implementation of an interface allows an invalid assignability check of the interface to pass
š Search Terms
assignability, unnecessary implementation
š Version & Regression Information
- This changed between versions 3.7.5 and 3.8.3
Itās still present in all versions including nightly.
āÆ Playground Link
Playground link with relevant code
Thanks @MartinJohns for the link
š» Code
interface Parent<A, B> {
getChild(): Child<A, B>;
iter(): Iterable<Parent<A, B>>;
}
interface Child<A, B>
extends Parent<A, B> {
readonly a: A;
readonly b: B;
}
class Impl<A, B> implements Parent<A, B> {
constructor(readonly child: Child<A, B>) {
}
getChild(): Child<A, B> {
return this.child;
}
*iter(): Iterable<Parent<A, B>> {
const map = new Map<Child<unknown, unknown>, Child<A, B>[]>();
function* gen(
inp: Child<A, B>
): Iterable<Child<A, B>> {
yield* map.get(inp) || [];
}
}
}
const x: Parent<unknown, unknown> = {} as any;
const _: Parent<null, unknown> = x; // should not pass
The final assignment should not pass. It accurately errors in 3.7.5, if the Impl
class is removed (or any aspect of the iter
implementation is modified), or by adding a sentinel type like sentinel?: A
to the Parent
interface to aid in type checking.
š Actual behavior
No error is thrown in the final assignment.
š Expected behavior
A n error is throw:
Type 'Parent<unknown, unknown>' is not assignable to type 'Parent<null, unknown>'.
Type 'unknown' is not assignable to type 'null'.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Investigations in intersection types:
14.29 Constraint solving rules to also handle non-unary type constructor ... In order to solve this problem, Russell [121] defined a theory.
Read more >Fundamental Approaches to Software Engineering
Integrating Topological Proofs with Model Checking to Instrument ... Automated Generation of Consistent Graph Models with First-Order Logic.
Read more >Efficiency Three Ways - School of Computer Science
checking dependent types is intricate, and, in the general case, undecidable. In short, this is because dependent types remove the isolation between valuesĀ ......
Read more >Information Technologyā Z Formal Specification Notationā Syntax ...
its decidable type system, which allows some well-formedness checks on a ... first word preceded by expression of non-unary function or generic.
Read more >Fundamental Approaches to Software ... - OAPEN Library
Integrating Topological Proofs with Model Checking to Instrument ... Note that ordering is dependent on the run time type. ... Java generics. Dyer...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Iāve spent the last 1.5 days debugging something that looks awfully like this one. This is way beyond my head and the understanding of the type system so I canāt fully assess if my issue is exactly the same or just similar. Therefore Iām going to post it, for the time being, to avoid creating a new issue that might be a duplicate of this one.
TS playground
code from the playground
Iāve also found out that this has changed between 3.7 and 3.8. More accurately - between
3.8.0-dev.20200117
and3.8.0-dev.20200118
. If only Iāve tracked down correctly from which commits those two were built then the behavior change is related to this diff: https://github.com/microsoft/TypeScript/compare/e2e1f6fd85b5076186ba6ee68fe59e11ccac1d3f..afa11d3c7ac37c49fc97230a897e4208ee132ae4 Given this diff, the change was introduced in this PR: https://github.com/microsoft/TypeScript/pull/36261I know that at this point Iām probably just reiterating what you probably already know but since Iāve already done this detective work Iām posting this here as a reference, just in case.
I also have a hunch that another issue that Iāve posted some months ago might be related to this one: https://github.com/microsoft/TypeScript/issues/45859 (I would have to confirm this when this one here gets fixed)
Simplified and cleaned up a little to make the violation more apparent