question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestion: Replace `any` with generic types to be able to match the actual and expected values

See original GitHub issue

Hey 👋

Thank you for the great library, I have one specific suggestion here regarding TypeScript

When I use assert.equal, I expect the types of actual and expects values to be the same or expects to be narrowed from actual

The explanation in Playground – https://tsplay.dev/NnXBxW

Do you think it makes sense and I can start working on that? I really want that change as I used it in jest but didn’t really like the experience (I needed to specify it myself to make it implicit)

WDYT?

Other solutions:

I see any for a lot of methods:

image

I want to cover it for at least:

  • is
  • equal
  • type
  • instance
  • snapshot (to be able to work with string literal types)
  • fixture (same as for snapshot)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
aicommented, Nov 29, 2021

It will be very cool to have the same typing on both side of is(a, b) and equal(a, b)

1reaction
lukeedcommented, Dec 9, 2021

Thanks for the progress @Beraliv ~! Turns out, this was all that was needed (similar idea as yours!):

declare function equal<T,U extends T = T>(a: T, b: U): asserts b is U;

Playground

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generic Types - Learning the Java Language
A generic type is a generic class or interface that is parameterized over types. The following Box class will be modified to demonstrate...
Read more >
Use generics to enforce same type properties in an array of an ...
I'm looking to use generics to enforce that the type of val1 should match the type of val2 for each element in an...
Read more >
Typescript forbids safety checks that check equality of values ...
When a function is passed two arguments of two different generic types, ... The real type of equality is <T>(x: T, y: T)...
Read more >
4.1. Generic Types - Java in a Nutshell, 5th Edition [Book]
In order to use a generic type like this, you specify actual types for the type variable (or variables), producing a parameterized type...
Read more >
Java Generics Example Tutorial - Generic Method, Class ...
We use <T> to create a generic class, interface, and method. The T is replaced with the actual type when we use it....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found