Use `any` instead of `unknown`
See original GitHub issueI’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:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Well, when I call
callMainI can specify data type for the data parameter that will be passed to the callback but inanswerRendererdefinition data parameter in callback is always defined asunknown(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.
@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.