Skip to content
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

core: refine typing of isObject<T> #12259

Merged
merged 5 commits into from
Mar 9, 2023
Merged

core: refine typing of isObject<T> #12259

merged 5 commits into from
Mar 9, 2023

Commits on Mar 4, 2023

  1. core: refine typing of isObject<T>

    The template parameter for `isObject` is currently used to force cast
    the value passed to the function, although there is no guarantee nor
    check done to ensure that this is really the case.
    
    This commit updates the typings so that the type passed to `isObject` is
    used to guide TypeScript during subsequent field type checking,
    assuming each field value is `unknown` and must also be type checked.
    
    Example:
    
    ```ts
    interface MyType {
        foo: string
    }
    
    const unknownValue: unknown = { foo: 2 };
    
    if (isObject<MyType>(unknownValue)) {
        // We enter this branch because `unknownValue` is indeed an object,
        // and TypeScript now knows we might want to access the `foo` field
        // from our interface. But we can't yet assume to know the type of
        // `foo`, so it is still typed as `unknown` and we must check:
        if (isString(unknownValue.foo)) {
            // We won't get in this branch. But if we did, then `foo` is
            // now properly typed (and checked) as `string`.
        }
    }
    ```
    paul-marechal committed Mar 4, 2023
    Configuration menu
    Copy the full SHA
    00f60fb View commit details
    Browse the repository at this point in the history

Commits on Mar 6, 2023

  1. simplify typings

    paul-marechal committed Mar 6, 2023
    Configuration menu
    Copy the full SHA
    bfe4d71 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2ae3688 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    e291789 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    62c8992 View commit details
    Browse the repository at this point in the history