Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions notNeededPackages.json
Original file line number Diff line number Diff line change
Expand Up @@ -7543,6 +7543,10 @@
"libraryName": "tedious",
"asOfVersion": "18.0.0"
},
"teen_process": {
"libraryName": "teen_process",
"asOfVersion": "4.0.0"
},
"temp-dir": {
"libraryName": "temp-dir",
"asOfVersion": "2.0.0"
Expand Down
4 changes: 3 additions & 1 deletion types/babel__code-frame/babel__code-frame-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import codeFrame, { codeFrameColumns } from "@babel/code-frame";
import codeFrame, { codeFrameColumns, highlight } from "@babel/code-frame";

const code = `
const number = 1;
Expand All @@ -24,3 +24,5 @@ codeFrameColumns(
{ start: { line: 2, column: 2 } },
{ highlightCode: true },
);

highlight(code);
9 changes: 9 additions & 0 deletions types/babel__code-frame/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ export default function codeFrame(
colNumber: number,
options?: BabelCodeFrameOptions,
): string;

/**
* Add syntax highlighting to a code snippet, to be displayed in a terminal.
*
* @param code Raw code to be highlighted
*
* @returns Highlighted code
*/
export function highlight(code: string): string;
2 changes: 1 addition & 1 deletion types/babel__code-frame/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/babel__code-frame",
"version": "7.0.9999",
"version": "7.27.9999",
"projects": [
"https://github.com/babel/babel/tree/master/packages/babel-code-frame",
"https://babeljs.io"
Expand Down
36 changes: 17 additions & 19 deletions types/express-serve-static-core/express-serve-static-core-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ app.route("/:foo").get(req => {
req.is(1);
});

// Params can used as an array
app.get<express.ParamsArray>("/*", req => {
req.params[0]; // $ExpectType string
req.params.length; // $ExpectType number
// Wildcard parameters return string arrays
app.get("/*foo", req => {
req.params.foo; // $ExpectType string[]
req.params.foo.length; // $ExpectType number
});

// Params can used as an array - under route
app.route("/*").get<express.ParamsArray>(req => {
req.params[0]; // $ExpectType string
req.params.length; // $ExpectType number
// Wildcard parameters return string arrays - under route
app.route("/*foo").get(req => {
req.params.foo; // $ExpectType string[]
req.params.foo.length; // $ExpectType number
});

// Params can be a custom type
Expand All @@ -74,10 +74,16 @@ app.route("/:foo/:bar").get<{ foo: string; bar: number }>(req => {
req.params.baz;
});

// Optional params
app.get("/:foo/:bar?", req => {
// Regular expressions have parameters that always are strings, never arrays of strings
app.get(/^\/(.*?)\|(?<b>\d+)/, req => {
req.params[0]; // $ExpectType string
req.params.foo; // $ExpectType string
});

// Regular expressions have parameters that always are strings, never arrays of strings - under route
app.route(/^\/(.*?)\|(?<b>\d+)/).get(req => {
req.params[0]; // $ExpectType string
req.params.foo; // $ExpectType string
req.params.bar; // $ExpectType string | undefined
});

// Express 5.0: Optional params
Expand Down Expand Up @@ -107,14 +113,6 @@ app.get("/:foo/:bar-:baz/:qux", req => {
req.params.quxx;
});

// regex parameters - not supported
app.get("/:foo/:bar(\\d:+)/:baz", req => {
req.params.foo; // $ExpectType string
req.params.bar; // $ExpectType string
req.params.qux; // $ExpectType string
req.params.quxx; // $ExpectType string
});

// long path parameters - https://github.com/DefinitelyTyped/DefinitelyTyped/pull/53513#issuecomment-870550063
app.get("/website-api/jobalarm/:jobalarmId/:subscriptionId/search", req => {
req.params.jobalarmId; // $ExpectType string
Expand Down
51 changes: 29 additions & 22 deletions types/express-serve-static-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ export interface Dictionary<T> {
}

export interface ParamsDictionary {
[key: string]: string;
[key: string]: string | string[];
[key: number]: string;
}
export type ParamsArray = string[];
export type Params = ParamsDictionary | ParamsArray;
export interface ParamsFlatDictionary {
[key: string | number]: string;
}
export type Params = ParamsDictionary | ParamsFlatDictionary;

export interface Locals extends Express.Locals {}

Expand Down Expand Up @@ -96,20 +99,26 @@ type GetRouteParameter<S extends string> = RemoveTail<
`.${string}`
>;

// prettier-ignore
export type RouteParameters<Route extends string> = Route extends `${infer Required}{${infer Optional}}${infer Next}`
? ParseRouteParameters<Required> & Partial<ParseRouteParameters<Optional>> & RouteParameters<Next>
: ParseRouteParameters<Route>;
// dprint-ignore
export type RouteParameters<Route extends string | RegExp> = Route extends string
? Route extends `${infer Required}{${infer Optional}}${infer Next}`
? ParseRouteParameters<Required> & Partial<ParseRouteParameters<Optional>> & RouteParameters<Next>
: ParseRouteParameters<Route>
: ParamsFlatDictionary;

type ParseRouteParameters<Route extends string> = string extends Route ? ParamsDictionary
: Route extends `${string}(${string}` ? ParamsDictionary // TODO: handling for regex parameters
: Route extends `${string}:${infer Rest}` ?
& (
GetRouteParameter<Rest> extends never ? ParamsDictionary
: GetRouteParameter<Rest> extends `${infer ParamName}?` ? { [P in ParamName]?: string } // TODO: Remove old `?` handling when Express 5 is promoted to "latest"
: { [P in GetRouteParameter<Rest>]: string }
)
& (Rest extends `${GetRouteParameter<Rest>}${infer Next}` ? RouteParameters<Next> : unknown)
: Route extends `${string}*${infer Rest}` ?
& (
GetRouteParameter<Rest> extends never ? ParamsDictionary
: { [P in GetRouteParameter<Rest>]: string[] }
)
& (Rest extends `${GetRouteParameter<Rest>}${infer Next}` ? RouteParameters<Next> : unknown)
: {};

/* eslint-disable @definitelytyped/no-unnecessary-generics */
Expand All @@ -118,7 +127,7 @@ export interface IRouterMatcher<
Method extends "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head" = any,
> {
<
Route extends string,
Route extends string | RegExp,
P = RouteParameters<Route>,
ResBody = any,
ReqBody = any,
Expand All @@ -131,7 +140,7 @@ export interface IRouterMatcher<
...handlers: Array<RequestHandler<P, ResBody, ReqBody, ReqQuery, LocalsObj>>
): T;
<
Path extends string,
Path extends string | RegExp,
P = RouteParameters<Path>,
ResBody = any,
ReqBody = any,
Expand Down Expand Up @@ -168,7 +177,7 @@ export interface IRouterMatcher<
(path: PathParams, subApplication: Application): T;
}

export interface IRouterHandler<T, Route extends string = string> {
export interface IRouterHandler<T, Route extends string | RegExp = string> {
(...handlers: Array<RequestHandler<RouteParameters<Route>>>): T;
(...handlers: Array<RequestHandlerParams<RouteParameters<Route>>>): T;
<
Expand Down Expand Up @@ -284,7 +293,7 @@ export interface IRouter extends RequestHandler {

use: IRouterHandler<this> & IRouterMatcher<this>;

route<T extends string>(prefix: T): IRoute<T>;
route<T extends string | RegExp>(prefix: T): IRoute<T>;
route(prefix: PathParams): IRoute;
/**
* Stack of configured routes
Expand All @@ -303,7 +312,7 @@ export interface ILayer {
handle: (req: Request, res: Response, next: NextFunction) => any;
}

export interface IRoute<Route extends string = string> {
export interface IRoute<Route extends string | RegExp = string> {
path: string;
stack: ILayer[];
all: IRouterHandler<this, Route>;
Expand Down Expand Up @@ -381,16 +390,14 @@ export type Errback = (err: Error) => void;

/**
* @param P For most requests, this should be `ParamsDictionary`, but if you're
* using this in a route handler for a route that uses a `RegExp` or a wildcard
* `string` path (e.g. `'/user/*'`), then `req.params` will be an array, in
* which case you should use `ParamsArray` instead.
*
* @see https://expressjs.com/en/api.html#req.params
* using this in a route handler for a route that uses a `RegExp`, then `req.params`
* will only contains strings, in which case you should use `ParamsFlatDictionary` instead.
*
* @example
* app.get('/user/:id', (req, res) => res.send(req.params.id)); // implicitly `ParamsDictionary`
* app.get<ParamsArray>(/user\/(.*)/, (req, res) => res.send(req.params[0]));
* app.get<ParamsArray>('/user/*', (req, res) => res.send(req.params[0]));
* app.get('/user/:id', (req, res) => res.send(req.params.id)); // implicitly `ParamsDictionary`, parameter is string
* app.get('/user/*id', (req, res) => res.send(req.params.id)); // implicitly `ParamsDictionary`, parameter is string[]
* app.get(/user\/(?<id>.*)/, (req, res) => res.send(req.params.id)); // implicitly `ParamsFlatDictionary`, parameter is string
* app.get(/user\/(.*)/, (req, res) => res.send(req.params[0])); // implicitly `ParamsFlatDictionary`, parameter is string
*/
export interface Request<
P = ParamsDictionary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@ app.route("/:foo").get(req => {
req.is(1);
});

// Params can used as an array
app.get<express.ParamsArray>("/*", req => {
req.params[0]; // $ExpectType string
req.params.length; // $ExpectType number
});

// Params can used as an array - under route
app.route("/*").get<express.ParamsArray>(req => {
req.params[0]; // $ExpectType string
req.params.length; // $ExpectType number
});

// Params can be a custom type
// NB. out-of-the-box all params are strings, however, other types are allowed to accommodate request validation/coercion middleware
app.get<{ foo: string; bar: number }>("/:foo/:bar", req => {
Expand Down
18 changes: 2 additions & 16 deletions types/express-serve-static-core/v4/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ export interface Dictionary<T> {
}

export interface ParamsDictionary {
[key: string]: string;
[key: string | number]: string;
}
export type ParamsArray = string[];
export type Params = ParamsDictionary | ParamsArray;
export type Params = ParamsDictionary;

export interface Locals extends Express.Locals {}

Expand Down Expand Up @@ -382,19 +381,6 @@ export interface RequestRanges extends RangeParserRanges {}

export type Errback = (err: Error) => void;

/**
* @param P For most requests, this should be `ParamsDictionary`, but if you're
* using this in a route handler for a route that uses a `RegExp` or a wildcard
* `string` path (e.g. `'/user/*'`), then `req.params` will be an array, in
* which case you should use `ParamsArray` instead.
*
* @see https://expressjs.com/en/api.html#req.params
*
* @example
* app.get('/user/:id', (req, res) => res.send(req.params.id)); // implicitly `ParamsDictionary`
* app.get<ParamsArray>(/user\/(.*)/, (req, res) => res.send(req.params[0]));
* app.get<ParamsArray>('/user/*', (req, res) => res.send(req.params[0]));
*/
export interface Request<
P = ParamsDictionary,
ResBody = any,
Expand Down
20 changes: 1 addition & 19 deletions types/express/express-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express = require("express");
import { ParamsArray, Request, RequestRanges } from "express-serve-static-core";
import { Request, RequestRanges } from "express-serve-static-core";
import * as http from "http";

namespace express_tests {
Expand Down Expand Up @@ -139,24 +139,6 @@ namespace express_tests {
req.params[0];
});

// Params can used as an array
router.get<ParamsArray>("/*", req => {
req.params[0]; // $ExpectType string
req.params.length; // $ExpectType number
});

// Params can used as an array and can be specified via an explicit param type (express-serve-static-core)
router.get("/*", (req: Request<ParamsArray>) => {
req.params[0]; // $ExpectType string
req.params.length; // $ExpectType number
});

// Params can used as an array and can be specified via an explicit param type (express)
router.get("/*", (req: express.Request<ParamsArray>) => {
req.params[0]; // $ExpectType string
req.params.length; // $ExpectType number
});

// Params can be a custom type
// NB. out-of-the-box all params are strings, however, other types are allowed to accomadate request validation/coersion middleware
router.get<{ foo: string; bar: number }>("/:foo/:bar", req => {
Expand Down
20 changes: 1 addition & 19 deletions types/express/v4/express-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express = require("express");
import { ParamsArray, Request, RequestRanges } from "express-serve-static-core";
import { Request, RequestRanges } from "express-serve-static-core";
import * as http from "http";

namespace express_tests {
Expand Down Expand Up @@ -146,24 +146,6 @@ namespace express_tests {
req.params[0];
});

// Params can used as an array
router.get<ParamsArray>("/*", req => {
req.params[0]; // $ExpectType string
req.params.length; // $ExpectType number
});

// Params can used as an array and can be specified via an explicit param type (express-serve-static-core)
router.get("/*", (req: Request<ParamsArray>) => {
req.params[0]; // $ExpectType string
req.params.length; // $ExpectType number
});

// Params can used as an array and can be specified via an explicit param type (express)
router.get("/*", (req: express.Request<ParamsArray>) => {
req.params[0]; // $ExpectType string
req.params.length; // $ExpectType number
});

// Params can be a custom type
// NB. out-of-the-box all params are strings, however, other types are allowed to accomadate request validation/coersion middleware
router.get<{ foo: string; bar: number }>("/:foo/:bar", req => {
Expand Down
2 changes: 1 addition & 1 deletion types/i18n/i18n-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ app.get("/ar", (_req: Express.Request, res: i18n.Response) => {
i18n.setLocale(res, "ar");
i18n.setLocale(res.locals, "ar");

i18n.setLocale([req, res.locals], req.params.lang);
i18n.setLocale([req, res.locals], "ar");
i18n.setLocale(res, "ar", true);
});

Expand Down
4 changes: 0 additions & 4 deletions types/lodash/common/lang.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,6 @@ declare module "../index" {
* @return Returns true if value is correctly classified, else false.
*/
isArray(value?: any): value is any[];
/**
* @see _.isArray
*/
isArray<T>(value?: any): value is any[];
}
interface LoDashImplicitWrapper<TValue> {
/**
Expand Down
2 changes: 1 addition & 1 deletion types/nodemailer/lib/mailer/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ declare namespace Mail {

interface Options {
/** The e-mail address of the sender. All e-mail addresses can be plain '[email protected]' or formatted 'Sender Name <[email protected]>' */
from?: string | Address | undefined;
from?: string | Address | Array<string | Address> | undefined;
/** An e-mail address that will appear on the Sender: field */
sender?: string | Address | undefined;
/** Comma separated list or an array of recipients e-mail addresses that will appear on the To: field */
Expand Down
11 changes: 11 additions & 0 deletions types/nodemailer/nodemailer-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ function message_common_fields_test() {
};
}

// Array variant of common fields

function message_common_fields_array_test() {
const message: Mail.Options = {
from: ["[email protected]", { address: "[email protected]", name: "Sender2" }],
to: ["[email protected]", { address: "[email protected]", name: "Receiver2" }],
cc: ["[email protected]"],
bcc: ["[email protected]"],
};
}

// More advanced fields

function message_more_advanced_fields_test() {
Expand Down
3 changes: 3 additions & 0 deletions types/react/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3564,6 +3564,9 @@ declare namespace React {
method?: string | undefined;
min?: number | string | undefined;
name?: string | undefined;
nonce?: string | undefined;
part?: string | undefined;
slot?: string | undefined;
style?: CSSProperties | undefined;
target?: string | undefined;
type?: string | undefined;
Expand Down
Loading