how do I turn an ES6 Proxy back into a plain object (POJO)?
I find a hack. In my case, I can’t control the creation of the proxy(mobx observable values). So the solution is: JSON.parse(JSON.stringify(your.object))
I find a hack. In my case, I can’t control the creation of the proxy(mobx observable values). So the solution is: JSON.parse(JSON.stringify(your.object))
Basically bar: ?string accepts a string, null or void: foo(“test”); foo(null); foo() While bar?: string Accepts only a string or void: foo(“test”); foo(); As passing null instead of a string is somewhat senseless, theres no real life difference between them.
Your Props type for Child is incorrect. React types the setIsActive as Dispatch, which is defined as: type Dispatch<A> = (value: A) => void; You’re missing the value argument from your type. This should be correct: type Props = { isActive: boolean; setIsActive: (active: boolean) => void; } const Child = ({ isActive, setIsActive}: Props) … Read more
It’s not necessarily true that a compiler/transpiler will always remove destructuring assignments as all evergreen browsers support destructuring natively as of 2020. As per, there is some evidence that as of at least 2018 the bytecode generated in V8 by a destructuring assignment is much more verbose than traditional function parameters: Function Parameters: function add(number1, … Read more
The rest parameter can only use at the end not anywhere else in the destructuring so it won’t work as you expected. Instead, you can destructor certain properties(an array is also an object in JS), for example, 0 for first and index of the last element for last. let array = [1,2,3,4,5,6,7,8,9,0] let {0 : … Read more
If your intention is to some other scope, iterate over it, do some other stuff, then be able to iterate over it again later on in that same scope. Then the only thing you shouldn’t try doing is passing the iterator, instead pass the generator: var generator = function*() { yield 1; yield 2; yield … Read more
expect(fn).toThrow() expects a function fn that, when called, throws an exception. However you are calling CheckFunctionExistenceByStr immediatelly, which causes the function to throw before running the assert. Replace test(` expect(CheckFunctionExistenceByStr( ‘any string’, ‘FunctionThatDoesNotExistsInString’ )).toThrow(); `, () => { expect(CheckFunctionExistenceByStr( ‘any string’, ‘FunctionThatDoesNotExistsInString’ )).toThrow(); } ); with test(` expect(() => { CheckFunctionExistenceByStr( ‘any string’, ‘FunctionThatDoesNotExistsInString’ ) … Read more
Chrome’s extension seems to rely on the resource name set in the URI, i.e the file.ext in protocol://domain/path/file.ext. So if your original URI contains that filename, the easiest might be to simply make your <object>’s data to the URI you fetched the pdf from directly, instead of going the Blob’s way. Now, there are cases … Read more
useRef is generic if you use it with TypeScript, so you can define the referenced element type like const ref = useRef<Type>(); Looking into the type definitions for the inputRef property in MaterialUI it states: /** * Pass a ref to the `input` element. */ inputRef?: React.Ref<any>; So for a fix you can define your … Read more
const data = { “key-with-dash”: [“BAZ”] } const {“key-with-dash”: foo} = data; console.log(“foo”, foo);