microsoft / react-native-windows

A framework for building native Windows apps with React.
https://microsoft.github.io/react-native-windows/
Other
16.34k stars 1.14k forks source link

Remove Global Leakage of winrt namespaces #4841

Open NickGerleman opened 4 years ago

NickGerleman commented 4 years ago

We have code today in shared headers that looks like this:

namespace winrt {
using namespace Windows::UI::Core;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
} // namespace winrt

This type of global leakage can lead to confusion of where namespaces are coming from, can leak to customers, and has bitten us in Office before, where incorrect types are silently included. E.g. the wrong IInspectable.

Cppcoreguidelines, which we try to follow explicitly calls this out as something not to do http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rs-using-directive

We should remove this, ensure it's not leaking to customers, and make namespace reduction explicit.

chrisglein commented 4 years ago

Will need to do an audit of where we're doing this. Coming up with that index seems like the next step. Solution used in tests: header file that has aliases that is included from cpp. Problem: interaction with PCHs.