Skip to content

Use this for SchemaInternals types#3115

Open
joshkel wants to merge 1 commit into
hapijs:masterfrom
joshkel:schema-this
Open

Use this for SchemaInternals types#3115
joshkel wants to merge 1 commit into
hapijs:masterfrom
joshkel:schema-this

Conversation

@joshkel
Copy link
Copy Markdown
Contributor

@joshkel joshkel commented May 14, 2026

Using this instead of Schema for methods that clone the input parameter is more precise - for example, calling $_addRule on a NumberSchema returns a NumberSchema.

$_setFlag was typed as returning void, but it returns an object of the same type. See example code at https://joi.dev/api/18.x.x#extensions.

Note that, as a type in TypeScript, "this refers dynamically to the type of the current class", so it can refer to a clone of the method's class as well as the class's own instance. See
https://www.typescriptlang.org/docs/handbook/2/classes.html#this-types

Using `this` instead of `Schema` for methods that clone the input
parameter is more precise - for example, calling `$_addRule` on a
NumberSchema returns a NumberSchema.

`$_setFlag` was typed as returning void, but it returns an object of the
same type. See example code at https://joi.dev/api/18.x.x#extensions.

Note that, as a type in TypeScript, "`this` refers dynamically to the
type of the current class", so it can refer to a clone of the method's
class as well as the class's own instance.  See
https://www.typescriptlang.org/docs/handbook/2/classes.html#this-types
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.

1 participant