Skip to content
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

Problem with expectAssignable and expectNotAssignable #190

Open
XadillaX opened this issue Mar 30, 2023 · 2 comments
Open

Problem with expectAssignable and expectNotAssignable #190

XadillaX opened this issue Mar 30, 2023 · 2 comments

Comments

@XadillaX
Copy link

XadillaX commented Mar 30, 2023

I have an interface like this:

import { NumbersToN } from 'ts-number-range';
type Byte = NumbersToN<256>;
interface RGBColor {
  r: Byte;
  g: Byte;
  b: Byte;
}

Then I test:

expectAssignable<RGBColor>({ r: 0, g: 0, b: 0 });  // ✅ it passes
expectAssignable<RGBColor>({ r: 0, g: 0, b: 256 });  // ✅ it failed
expectNotAssignable<RGBColor>({ r: 0, g: 0, b: 0 });  // ❌ it passes
expectNotAssignable<RGBColor>({ r: 0, g: 0, b: 256 });  // ✅ it passes

It seems expectNotAssignable<RGBColor>({ r: 0, g: 0, b: 0 }) not work correctly.

@mrazauskas
Copy link
Contributor

Did you try:

expectAssignable<RGBColor>({r: 0, g: 0, b: 0} as const);
expectAssignable<RGBColor>({r: 0, g: 0, b: 256} as const);

expectNotAssignable<RGBColor>({r: 0, g: 0, b: 0} as const);
expectNotAssignable<RGBColor>({r: 0, g: 0, b: 256} as const);

Because:

Screenshot 2023-03-30 at 10 38 56

But:

Screenshot 2023-03-30 at 10 38 42

@XadillaX
Copy link
Author

Did you try:

expectAssignable<RGBColor>({r: 0, g: 0, b: 0} as const);
expectAssignable<RGBColor>({r: 0, g: 0, b: 256} as const);

expectNotAssignable<RGBColor>({r: 0, g: 0, b: 0} as const);
expectNotAssignable<RGBColor>({r: 0, g: 0, b: 256} as const);

Because:

Screenshot 2023-03-30 at 10 38 56

But:

Screenshot 2023-03-30 at 10 38 42

It works after I adding as const.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants