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.

Use `any` instead of `unknown`

See original GitHub issue

I’m working on https://github.com/sindresorhus/caprine/issues/848 and I’ve hit a wall when I wanted to receive data from answerRendered function. The problem is passed data is defined in answerRenderer with unknown type which can’t later on be assigned to other values with any other type than unknown.

My best idea is to use type any instead of unknown. Other option is to use unknown type on every ipc handling in Caprine which doesn’t sound very nice to me.

@BendingBender I’d love your thoughts on this too since you wrote up TypeScript definitions.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dusansimiccommented, Oct 8, 2019

Well, when I call callMain I can specify data type for the data parameter that will be passed to the callback but in answerRenderer definition data parameter in callback is always defined as unknown (generic type cannot change it) hence the error is thrown.

A two generic types would be useful since then, developer can specify both the type of data that is received and the type of data that is sent back.

0reactions
vladimirycommented, Nov 19, 2019

@dusansimic you could try https://github.com/vladimiry/electron-rpc-api if you need methods signatures, including the payload type, to be fully typed/predefined.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'unknown' vs. 'any' - typescript - Stack Overflow
unknown which is the type-safe counterpart of any. Anything is assignable to unknown, but unknown isn't assignable to anything but itself and ...
Read more >
unknown vs any in TypeScript - Dmitri Pavlutin
unknown is recommended over any because it provides safer typing — you have to use type assertion or narrow to a specific type...
Read more >
Typescript - why to use "unknown" instead of "any"
unknown is just pessimistic 'any' . With any , ts is like "maybe it is of type array, who knows?", and with unknown...
Read more >
Typescript: why you should use unknown instead of any
The unknown type, when assigned to a variable, means that a variable type is not known. And typescript doesn't allow you to use...
Read more >
TypeScript: Any vs Unknown vs Never | by Jose Granja
In summary, unknown is the preferred alternative to any and can be used to better express general types. It can be narrowed down...
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