sindresorhus / is

Type check values
MIT License
1.68k stars 109 forks source link

Add `.isWeakRef()` #165

Closed bigbigDreamer closed 2 years ago

bigbigDreamer commented 2 years ago

@sindresorhus done other PR to replace #164

sindresorhus commented 2 years ago

Tests are failing

bigbigDreamer commented 2 years ago

Tests are failing

Sorry, I haven't checked the problem yet. At present, it seems that only node version 14 is passed.

bigbigDreamer commented 2 years ago

Tests are failing

image

I found the reason, because JSDOM WeakRef currently supports V14.6.0+ , can I Mock one manually? As a downgrade solution to handle Node versions?

bigbigDreamer commented 2 years ago

Unfortunately, I have not found a solution on how to simulate the behavior of WeakRef. At present, because JSOM simulation is limited to Node V14.6.0+, the test of the lower version fails, so I can only temporarily close this PR, thank you for your understanding

bigbigDreamer commented 2 years ago

https://github.com/ungap/weakrefs/blob/master/cjs/index.js perhaps it can try mock in node env

bigbigDreamer commented 2 years ago

Although the use case must be run on a low version node environment, the minimum requirement for WeakRef is Node V14.6.0, so I don't think it is necessary to create a mock use case for it on a low version Node.

bigbigDreamer commented 2 years ago

Record: JSDOM@latest will reported error in ci with Node V10.

image
bigbigDreamer commented 2 years ago

Tests all pass, @sindresorhus 🥳

sindresorhus commented 2 years ago

Can you fix the merge conflict?

bigbigDreamer commented 2 years ago

Can you fix the merge conflict?

Ok. Had fixed!But I encountered a very strange problem. Line 343 is a blank line, but lint reported an error. I repeatedly checked the code and found no problems. Can I ask for your help.

image
sindresorhus commented 2 years ago

I suggest we just embed the WeakRef type so we don't have to require a higher target.

interface WeakRef<T extends object> {
    readonly [Symbol.toStringTag]: "WeakRef";

    /**
     * Returns the WeakRef instance's target object, or undefined if the target object has been
     * reclaimed.
     */
    deref(): T | undefined;
}
bigbigDreamer commented 2 years ago

I suggest we just embed the WeakRef type so we don't have to require a higher target.

interface WeakRef<T extends object> {
    readonly [Symbol.toStringTag]: "WeakRef";

    /**
     * Returns the WeakRef instance's target object, or undefined if the target object has been
     * reclaimed.
     */
    deref(): T | undefined;
}

done

bigbigDreamer commented 2 years ago

Can you fix the merge conflict?

Ok. Had fixed!But I encountered a very strange problem. Line 343 is a blank line, but lint reported an error. I repeatedly checked the code and found no problems. Can I ask for your help.

image

Thank you so much, I just noticed that I read the wrong file, it is a lint problem in another file, sorry, sorry for the trouble, I will be more careful next time