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

types: use globalThis instead of global for NativeDate #14992

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

Bl4sio
Copy link
Contributor

@Bl4sio Bl4sio commented Oct 29, 2024

Fix: #14988

Summary

The global is defined in the @types/node package, which is not in the dependencies. Without the package, NativeDate would be interpreted as any by typescript, and resolves the types in the Schema incorrectly.

Examples

import { Schema, Types } from "mongoose";

interface IUser {
  organization: Types.ObjectId;
}

const userSchema = new Schema<IUser>({
  // typescript error: Type 'typeof ObjectId' is not assignable to type 'DateSchemaDefinition | typeof Mixed | undefined'.
  organization: { type: Schema.Types.ObjectId, ref: "Organization" },
});

Fix for issue Automattic#14988 
The global is defined in the @types/node package, which is not in the dependencies.
Without the package, NativeDate would be interpreted as any by typescript, and resolves the types in the Schema incorrectly.
@vkarpov15 vkarpov15 added this to the 8.8 milestone Oct 29, 2024
@vkarpov15 vkarpov15 merged commit 91ed8c3 into Automattic:master Oct 29, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating a schema corresponding to an interface containing a reference causes a Typescript error
2 participants