You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function queryOutsideWorld(queryName) : unsafe {
// ... some fetch() or RPC call
// ... some JSON.parse()
// ... extract body with random interface
return someRandomData
}
// fail
let data = queryOutsideWorld('user-profile')
// ok
let data: UserProfile = queryOutsideWorld('user-profile')
I've read similar issues and the closest one is the unknown type #10715. However I believe there is room for a less complex solution.
Currently if I fetch something from the outside world I must do some kind of runtime validation and cast to a known type / interface. If I start looking for common functionality I will be forced to create functions and even libraries that must return any but I would like a way return a value and force the programmer to do an explicit cast.
In my example I've used a new type keyword as a basic example, but I would rather like to have something where I can define unsafe subtypes such has:
// global.d.ts
type Unsafe extends any as unsafe
type RiskyAny extends any;
if (process.env.NODE_ENV === 'production') {
type RiskyAny extends any as unsafe;
}
This would enable a second case. I want to prototype code/ideas in a non very strict environment, and only increase the typing-strictness later, if/when the library "matures". There is code that is OK to have type any in development, but in production (or at a more mature version) it will have to go away before other any types
The text was updated successfully, but these errors were encountered:
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.8.3
Search Terms:
Code
Related Issues:
#10715
#22716
#9999
I've read similar issues and the closest one is the
unknown
type #10715. However I believe there is room for a less complex solution.Currently if I fetch something from the outside world I must do some kind of runtime validation and cast to a known type / interface. If I start looking for common functionality I will be forced to create functions and even libraries that must return
any
but I would like a way return a value and force the programmer to do an explicit cast.In my example I've used a new type keyword as a basic example, but I would rather like to have something where I can define unsafe subtypes such has:
This would enable a second case. I want to prototype code/ideas in a non very strict environment, and only increase the typing-strictness later, if/when the library "matures". There is code that is OK to have type
any
in development, but in production (or at a more mature version) it will have to go away before otherany
typesThe text was updated successfully, but these errors were encountered: