New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@types/react] Remove calculateChangedBits from createContext #44886
Comments
would you be satisfied if it were just named appropriately (without moving it)? We did so for other such examples recently. Or is moving to the experimental definition the main thing you'd like to achieve here? It seems to me (and would be my 2 cents) that removing it altogether is a last resort - and it instead belongs in the |
Would be happy to contribute either of these options; I think the On the other hand removing it entirely from the main definition could very likely make some CI builds break. |
It would make more sense to just remove it and advise people to use declaration merging for unstable APIs. This would at least work for this specific case: import * as React from 'react';
// unstable APIs
declare module 'react' {
function createContext<T>(
defaultValue: T,
unstable_calculateChangedBits?: (prev: T, next: T) => number
): Context<T>;
} @gaearon What about other unstable APIs in the stable bundle like |
My main concern is Code aggressively autocompleting parameters that aren't supposed to be used. Which arguably is more of a Code issue. I guess for function arguments this is worse than for JSX props. Overall, I think if something is not in the docs, it should not be in the typings either. People who want to use it can always |
An alternative would also be to use JSDoc to specifically mark the second parameter as deprecated, though it would do less to prevent people from using it. |
I think that it's even worse for props than for function arguments if unstable parameters are added via function overload. For props you always get the full interface which lists the unstable props. For functions you either have to explicitly start typing the additional parameter or go through each overload: -- demo Personally I'm fine with removing unstable APIs from the typings and recommend declaration merging. It's what we recommend for non-standard HTML attributes as well. I was never a fan of the recommended "link to source to justify typings"-approach of DefinitelyTyped. If React core members support this we have an easier time defending the change. |
👍 |
Authors: @johnnyreilly @bbenezech @pzavolinsky @digiguru @ericanderson @DovydasNavickas @theruther4d @guilhermehubner @ferdaber @jrakotoharisoa @pascaloliv @Hotell @franklixuefei @Jessidhia @saranshkataria @lukyth @eps1lon @zieka @dancerphil @dimitropoulos @disjukr @vhfmag
I've just noticed
createContext
has a second argument in the type definition. This doesn't make sense and is misleading. That second argument is an unstable API that will likely be removed. It's calledunstable_calculateChangedBits
but the definition just calls itcalculateChangedBits
. What's worse, VS Code autocomplete offers to supply it. Could we remove the unstable API from typings or move this overload to the experimental definition?The text was updated successfully, but these errors were encountered: