-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Types declared as an "interface" do not extend Record<PropertyKey, unknown> #42825
Comments
Types declared with See #41518. |
@MartinJohns Good point, but why does it type TFoo = {
type: string;
value: number;
};
interface IFoo {
type: string;
value: number;
}
type TFooCheck = TFoo extends Record<PropertyKey, any> ? true : false; // => true
type IFooCheck = IFoo extends Record<PropertyKey, any> ? true : false; // => true |
Any object type is assignable to |
Could someone explain this in more detail? Yes, all properties of type TFoo = {
type: string;
value: number;
};
interface IFoo {
type: string;
value: number;
}
type IFooCheckAny = IFoo extends Record<PropertyKey, any> ? true : false; // => true
type IFooCheckUnknown = IFoo extends Record<PropertyKey, unknown> ? true : false; // => false
type TFooCheckUnknown = TFoo extends Record<PropertyKey, unknown> ? true : false; // => true |
This is exactly the train of thought that lead to anything being assignable to |
Crosslinking #15300 |
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
*Checked 4.1.3, 4.1.5, current beta, nightly, and some previous versions.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
InterfaceTest
andInterfaceTypeTest
(all variations) are assigned the type offalse
, while the variousTypeTests
all returntrue
.Additionally,
fooInterface
andfooInterfaceType
fails type check when passed to the stub functioncheckObject()
with the error code 2345 (missing index signature).🙂 Expected behavior
TypeTest
,InterfaceTest
, andInterfaceTypeTest
(all variations) should be assigned the typetrue
, and the three usages of the functioncheckObject()
passes type check.My understanding of
unknown
is that every type extendsunknown
(likeany
) andunknown
extends onlyunknown
, so object types of any shape should extendRecord<PropertyKey, unknown>
. From this is why I think the correct result is that all 3 variants ofFoo
extendsRecord<PropertyKey, unknown>
.Also, even if that assumption is incorrect, the types
TFoo
andIFoo
only differ in that they're declared as atype
or aninterface
. I expect that this means thatTFoo
andIFoo
should be treated identically by various type constraints.I initially encountered this issue when I was trying to pass an object with an interface-declared type to a function in the Deno standard library (specifically
assertObjectMatch()
under "testing/asserts" which accepts two arguments of typeRecord<PropertyKey, unknown>
).The text was updated successfully, but these errors were encountered: