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
12 changes: 6 additions & 6 deletions types/mithril/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ declare namespace Mithril {
}

interface Hyperscript {
/** Creates a virtual element (Vnode). */
(selector: string, attributes: Attributes, ...children: Children[]): Vnode<any, any>;
/** Creates a virtual element (Vnode). */
(selector: string, ...children: Children[]): Vnode<any, any>;
/** Creates a virtual element (Vnode). */
<Attrs, State>(component: ComponentTypes<Attrs, State>, ...args: Children[]): Vnode<Attrs, State>;
/** Creates a virtual element (Vnode). */
<Attrs, State>(
component: ComponentTypes<Attrs, State>,
attributes: Attrs & CommonAttributes<Attrs, State>,
...args: Children[]
): Vnode<Attrs, State>;
/** Creates a virtual element (Vnode). */
(selector: string, attributes: Attributes, ...children: Children[]): Vnode<any, any>;
/** Creates a virtual element (Vnode). */
<Attrs, State>(component: ComponentTypes<Attrs, State>, ...args: Children[]): Vnode<Attrs, State>;
/** Creates a virtual element (Vnode). */
(selector: string, ...children: Children[]): Vnode<any, any>;
/** Creates a fragment virtual element (Vnode). */
fragment(
attrs: CommonAttributes<any, any> & { [key: string]: any },
Expand Down
15 changes: 15 additions & 0 deletions types/mithril/test/test-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ m(comp2, { title: "", description: "" });
// Correct use with lifecycle method
m(comp2, { title: "", description: "", oncreate: v => `${v.attrs.title}\n${v.attrs.description}` });

// Component attribute diagnostics
interface NumberComponentAttrs {
min: number;
}

const numberComponent: Component<NumberComponentAttrs> = {
view() {
return null;
},
};

// Type 'string' is not assignable to type 'number'.
// @ts-expect-error
m(numberComponent, { min: "x" });

// Properties missing
// @ts-expect-error
m(comp2, {});
Expand Down
18 changes: 9 additions & 9 deletions types/negotiator/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,67 @@ declare class Negotiator {
* @param [availableMediaTypes] When provided, returns the most preferred media type
* from a list of available media types.
*/
mediaType(availableMediaTypes?: string[]): string | undefined;
mediaType(availableMediaTypes?: readonly string[]): string | undefined;

/**
* Returns an array of preferred media types ordered by the client preference
*
* @param [availableMediaTypes] When provided, returns an array of preferred media
* types ordered by priority from a list of available media types.
*/
mediaTypes(availableMediaTypes?: string[]): string[];
mediaTypes(availableMediaTypes?: readonly string[]): string[];

/**
* Returns the most preferred language from the client.
*
* @param [availableLanguages] When provided, returns the most preferred language
* from a list of available languages.
*/
language(availableLanguages?: string[]): string | undefined;
language(availableLanguages?: readonly string[]): string | undefined;

/**
* Returns an array of preferred languages ordered by the client preference.
*
* @param [availableLanguages] When provided, returns an array of preferred languages
* ordered by priority from a list of available languages.
*/
languages(availableLanguages?: string[]): string[];
languages(availableLanguages?: readonly string[]): string[];

/**
* Returns the most preferred charset from the client.
*
* @param [availableCharsets] When provided, returns the most preferred charset
* from a list of available charsets.
*/
charset(availableCharsets?: string[]): string | undefined;
charset(availableCharsets?: readonly string[]): string | undefined;

/**
* Returns an array of preferred charsets ordered by the client preference.
*
* @param [availableCharsets] When provided, returns an array of preferred charsets
* ordered by priority from a list of available charsets.
*/
charsets(availableCharsets?: string[]): string[];
charsets(availableCharsets?: readonly string[]): string[];

/**
* Returns the most preferred encoding from the client.
*
* @param [availableEncodings] When provided, returns the most preferred encoding
* from a list of available encodings.
*/
encoding(availableEncodings?: string[]): string | undefined;
encoding(availableEncodings?: readonly string[]): string | undefined;

/**
* Returns an array of preferred encodings ordered by the client preference.
*
* @param [availableEncodings] When provided, returns an array of preferred encodings
* ordered by priority from a list of available encodings.
*/
encodings(availableEncodings?: string[]): string[];
encodings(availableEncodings?: readonly string[]): string[];
}

declare namespace Negotiator {
interface Headers {
[key: string]: string | string[] | undefined;
readonly [key: string]: string | (readonly string[]) | undefined;
}
}
10 changes: 5 additions & 5 deletions types/negotiator/negotiator-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ const request = {
"Accept-Charset": "utf-8, iso-8859-1;q=0.8, utf-7;q=0.2",
"Accept-Encoding": "gzip, compress;q=0.2, identity;q=0.5",
},
};
} as const;

const negotiator = new Negotiator(request);

const availableMediaTypes = ["text/html", "text/plain", "application/json"];
const availableMediaTypes = ["text/html", "text/plain", "application/json"] as const;
// $ExpectType string[]
negotiator.mediaTypes();
negotiator.mediaTypes(availableMediaTypes);
// $ExpectType string | undefined
negotiator.mediaType();
negotiator.mediaType(availableMediaTypes);

const availableLanguages = ["en", "es", "fr"];
const availableLanguages = ["en", "es", "fr"] as const;
// $ExpectType string[]
negotiator.languages();
negotiator.languages(availableLanguages);
// $ExpectType string | undefined
negotiator.language();
negotiator.language(availableLanguages);

const availableCharsets = ["utf-8", "iso-8859-1", "iso-8859-5"];
const availableCharsets = ["utf-8", "iso-8859-1", "iso-8859-5"] as const;
// $ExpectType string[]
negotiator.charsets();
negotiator.charsets(availableCharsets);
// $ExpectType string | undefined
negotiator.charset();
negotiator.charset(availableCharsets);

const availableEncodings = ["identity", "gzip"];
const availableEncodings = ["identity", "gzip"] as const;
// $ExpectType string[]
negotiator.encodings();
negotiator.encodings(availableEncodings);
Expand Down