-
Notifications
You must be signed in to change notification settings - Fork 8
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
Feature request: (maybe) rename .toMatchTypeOf
#10
Comments
.toBeSubtypeOf
and .toBeSupertypeOf
.toMatchTypeOf
I'd like to separate out the idea of Options as I see them: (Also @papb I've invited you as a collaborator, which (maybe) will allow you to edit this comment, so if you think of another option, you can add here)
I think 2 probably is the best, aside from toMatchTypeOf already existing and being in use quite a lot. Maybe it could be kept around as an alias though, although I also don't love doing that. |
Yeah, I also like One example I ran into recently with expectNotAssignable<{[key: `#${string}`]: string}>({'missingLeading#': 'oops'}); In expectTypeOf({'missingLeading#': 'oops'}).not.toMatchTypeOf<{[key: `#${string}`]: string}>(); And the following does: expectTypeOf({'missingLeading#': 'oops'}).toMatchTypeOf<{[key: `#${string}`]: string}>(); You can verify proper TS assignability in vanilla TS with something like: function expectAssignable<Expected = never, Actual extends Expected = Expected>(arg: Actual) {} (The extra generic param prevents Used like: expectAssignable<{[key: `#${string}`]: string}>({'#withLeading': 'yay'}); As far as I'm aware, you can't write vanilla TS for |
I was very happy to see the invite, @mmkal, thank you very much 😁
None comes to mind 😅 I also prefer option 2.
I also think it can be kept around as an alias, but with |
Why? You mean the fact that excess properties are allowed in object assignments in some cases? To be honest I don't remember well what are the exact situations in which excess properties are allowed. But I noticed that your vanilla // @ts-expect-error
expectAssignable<{[key: `#${string}`]: string}>({'trailing#': 'oops'}); The PR you linked shows that even tsd's So maybe you're talking about something else, not excess properties? Sorry 😅 |
Re: Basically I'm wondering if you could mimic it with a |
Also, by the way, maybe the new |
I'm not against doing this still, but I think I will release a v1 with the API pretty much as it is since it has a decent amount of usage already, so it shouldn't really be on v0 anymore. This can go into a v2 someday. |
Update for anyone interested - I am now leaning towards deprecating PR: #126. Example: type MyType = {readonly a: string; b: number; c: {some: {very: {complex: 'type'}}}; d?: boolean}
expectTypeOf<MyType>().toMatchObjectType<{a: string; b: number}>() // fails - forgot readonly
expectTypeOf<MyType>().toMatchObjectType<{readonly a: string; b?: number}>() // fails - b shouldn't be optional
expectTypeOf<MyType>().toMatchObjectType<{readonly a: string; d: boolean}>() // fails - d should be optional
expectTypeOf<MyType>().toMatchObjectType<{readonly a: string; b: number}>() // passes
expectTypeOf<MyType>().toMatchObjectType<{readonly a: string; d?: boolean}>() // passes This still isn't |
Hi @mmkal! In mmkal/ts#30 I asked for clarification on
.toMatchTypeOf
, because its meaning wasn't clear to me from the name alone. You've updated the documentation and it is clear after reading it, but now that some time passed I had to check again because I again wasn't sure.Original request
I'd like to request the addition of
.toBeSubtypeOf
as an alias to.toMatchTypeOf
, and also request the addition of.toBeSupertypeOf
while you're at it. What do you think?The text was updated successfully, but these errors were encountered: