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

test not working when Record type with default param #167

Open
usageness opened this issue Sep 27, 2022 · 2 comments
Open

test not working when Record type with default param #167

usageness opened this issue Sep 27, 2022 · 2 comments

Comments

@usageness
Copy link

While testing custom type, I met some bug like this:

it("ObjectType type test", () => {
type ObjectType<T, K extends string | number | symbol = string> = Record<
  K,
  T
>;
  // given & when
  const result = { a: "1", b: "2", c: "3", d: "4", e: "5" };

  // then
  expectType<ObjectType<string>>(result); // test passed
  expectType<ObjectType<string, symbol>>(result); // test passed
  expectType<ObjectType<string, number>>(result); // test passed
  expectNotType<ObjectType<string, number>>(result); // test passed
}

I think, may be there's something problem in checking types with default param.
So I check another test case.

normal case

type TestType<T extends string | number> = Record<T, string>;
const test = { a: 1 };

expectType<TestType<string>>(test);  // ide warn, test failed
expectNotType<TestType<string>>(test);

problem case

type TestType<T extends string | number = string> = Record<T, string>;
const test = { a: 1 };

expectType<TestType<string>>(test);  // ide warn, but test passed
expectNotType<TestType<string>>(test);  // test passed
type TestType<K, T extends string | number = string> = Record<T, K>;
const test = { a: 1 };

expectType<TestType<string, number>>(test);  // no warning, test passed
expectNotType<TestType<string, number>>(test);  // test passed, problem occurred!

Can anyone please explain this result?

@LAH1203
Copy link

LAH1203 commented Sep 28, 2022

Me too!

@skarab42
Copy link
Contributor

Duplicate of #142 but fixed in the new API proposal #168

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

3 participants