2 ms·
Yes - trying to access a property or method on something typed as unknown will (almost?) always result in a compile time error because it's unknown whether the
by madeofpalk 4y ago
Yes - trying to access a property or method on something typed as unknown will (almost?) always result in a compile time error because it's unknown whether the value has that property or not.
https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAdwE4EMAOBhBBnOAGwFMAZOAcwEEwBPACigAsYwKAVOcigLkXToBKRAG8AUIkQR8RYgDpClegCIAsrUQB1YgCNEVTJmUAaRM1YculOVDgBVQ8VTZ0eYvUGCxAXzFjQkLAIKBg4MiTcdmAA1mBwyGCMLGyc3HzgsfFgwuKS0mAEJApKahraegZGpuYpVhQ29o7Oru6ePn4B0PBIaFi4BbKRMXEJAELEUFBOSRaplOnDWTkSiDDAiIy0mMRw6zWW3IgAvCeIynhQqBbKy5J54fKKFCrqWrr6hiZmyQfWtg7bZpuDxeSTeRDEQhuUQre4DIpPF5ld6VL77OYUUGIXzeIA https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAd...
- thoughtspile 4y agoalways, because "unknown" includes null / undefined, which don't allow property access at all.