Replace any by unknown in definition files
See original GitHub issueSince the new unknown
type was added, it makes sense to replace a lot (if not all) usage of any
in the definition files with unknown
. For example:
Array.isArray(a: unknown): a is unknown[];
JSON.parse(a: string): unknown;
However, this change will cause many errors in projects currently using the fact that the returned types are not type-checked. This means that the change could be controversial.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:51
- Comments:16 (8 by maintainers)
Top Results From Across the Web
How to replace unknown values inside a file in python
As suggested by @Barmar, use a regex to replace your text: import re PAT = re.compile('image: ".*\.png"') with open('readme.json') as inp, ...
Read more >Use the Find and Replace dialog box to change data
In the Find What box, type your search value. To replace data, type a replacement string in the Replace With box. Note: Do...
Read more >kubectl replace - Kubernetes
Replace a resource by filename or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must...
Read more >Dependency resolution - Parcel
As Parcel builds your source code, it discovers dependencies, which allow code to be broken into separate files and reused in multiple places....
Read more >Documentation - Module Resolution - TypeScript
json named types to mirror the purpose of "main" - the compiler will use it to find the “main” definition file to consult....
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
This is one of the biggest blind spots regarding type safety in big codebases. You can warn against using explicit
any
with linting, but you can’t change the types of all the declaration files@RyanCavanaugh now that you’ve backed off from strictAny, would you reconsider this? The original use case here (which motivated strictAny in the first place) would still be pretty valuable.