This question was split from questions/72839100 per @jcalz's comment.
In the following snippet,
declare const foo: Record<string, string>;
declare function bar(foo: Record<string, string>): asserts foo is {};
bar(foo);
foo;
// ^?
foo
is {}
(so foo.prop
yields an error) but in
declare const foo: Record<string, string>;
declare function bar<T>(foo: T): asserts foo is T & {};
bar(foo);
foo;
// ^?
foo
is Record<string, string>
(thus foo.prop
works).
Is it working as intended that the type inference of foo
is different in these two cases due to the presence of intersection in type predicate, because Record<string, string> & {}
resolves to {}
, as in the question mentioned above? Why TypeScript doesn't do a intersection internally, such that a manual intersection becomes necessary?