* Improve typescript null checking in places * Iterate * Fix Timer.ts
This commit is contained in:
parent
97506cbcdb
commit
9743852380
43 changed files with 155 additions and 154 deletions
|
@ -70,7 +70,7 @@ export default abstract class AutocompleteProvider {
|
|||
* @param {boolean} force True if the user is forcing completion
|
||||
* @return {object} { command, range } where both objects fields are null if no match
|
||||
*/
|
||||
public getCurrentCommand(query: string, selection: ISelectionRange, force = false): ICommand {
|
||||
public getCurrentCommand(query: string, selection: ISelectionRange, force = false): ICommand | null {
|
||||
let commandRegex = this.commandRegex;
|
||||
|
||||
if (force && this.shouldForceComplete()) {
|
||||
|
@ -83,7 +83,7 @@ export default abstract class AutocompleteProvider {
|
|||
|
||||
commandRegex.lastIndex = 0;
|
||||
|
||||
let match: RegExpExecArray;
|
||||
let match: RegExpExecArray | null;
|
||||
while ((match = commandRegex.exec(query)) !== null) {
|
||||
const start = match.index;
|
||||
const end = start + match[0].length;
|
||||
|
|
|
@ -87,7 +87,7 @@ export default class Autocompleter {
|
|||
to predict whether an action will actually do what is intended
|
||||
*/
|
||||
// list of results from each provider, each being a list of completions or null if it times out
|
||||
const completionsList: ICompletion[][] = await Promise.all(
|
||||
const completionsList: Array<ICompletion[] | null> = await Promise.all(
|
||||
this.providers.map(async (provider): Promise<ICompletion[] | null> => {
|
||||
return timeout(
|
||||
provider.getCompletions(query, selection, force, limit),
|
||||
|
@ -113,6 +113,6 @@ export default class Autocompleter {
|
|||
command: this.providers[i].getCurrentCommand(query, selection, force),
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
.filter(Boolean) as IProviderCompletions[];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,10 +56,10 @@ export default class CommandProvider extends AutocompleteProvider {
|
|||
if (command[0] !== command[1]) {
|
||||
// The input looks like a command with arguments, perform exact match
|
||||
const name = command[1].slice(1); // strip leading `/`
|
||||
if (CommandMap.has(name) && CommandMap.get(name).isEnabled()) {
|
||||
if (CommandMap.has(name) && CommandMap.get(name)!.isEnabled()) {
|
||||
// some commands, namely `me` don't suit having the usage shown whilst typing their arguments
|
||||
if (CommandMap.get(name).hideCompletionAfterSpace) return [];
|
||||
matches = [CommandMap.get(name)];
|
||||
if (CommandMap.get(name)!.hideCompletionAfterSpace) return [];
|
||||
matches = [CommandMap.get(name)!];
|
||||
}
|
||||
} else {
|
||||
if (query === "/") {
|
||||
|
|
|
@ -39,12 +39,12 @@ function canonicalScore(displayedAlias: string, room: Room): number {
|
|||
|
||||
function matcherObject(
|
||||
room: Room,
|
||||
displayedAlias: string,
|
||||
displayedAlias: string | null,
|
||||
matchName = "",
|
||||
): {
|
||||
room: Room;
|
||||
matchName: string;
|
||||
displayedAlias: string;
|
||||
displayedAlias: string | null;
|
||||
} {
|
||||
return {
|
||||
room,
|
||||
|
@ -58,7 +58,7 @@ export default class RoomProvider extends AutocompleteProvider {
|
|||
|
||||
public constructor(room: Room, renderingType?: TimelineRenderingType) {
|
||||
super({ commandRegex: ROOM_REGEX, renderingType });
|
||||
this.matcher = new QueryMatcher([], {
|
||||
this.matcher = new QueryMatcher<ReturnType<typeof matcherObject>>([], {
|
||||
keys: ["displayedAlias", "matchName"],
|
||||
});
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ export default class RoomProvider extends AutocompleteProvider {
|
|||
const { command, range } = this.getCurrentCommand(query, selection, force);
|
||||
if (command) {
|
||||
// the only reason we need to do this is because Fuse only matches on properties
|
||||
let matcherObjects = this.getRooms().reduce((aliases, room) => {
|
||||
let matcherObjects = this.getRooms().reduce<ReturnType<typeof matcherObject>[]>((aliases, room) => {
|
||||
if (room.getCanonicalAlias()) {
|
||||
aliases = aliases.concat(matcherObject(room, room.getCanonicalAlias(), room.name));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue