fix type assertion

This commit is contained in:
kakkokari-gtyih 2024-12-29 12:31:12 +09:00
parent 16cdcf24ad
commit a7d3a34103
5 changed files with 22 additions and 11 deletions

View File

@ -49,7 +49,12 @@ describe('Timeline', () => {
async () => { async () => {
note = (await alice.client.request('notes/create', { text, ...noteParams })).createdNote; note = (await alice.client.request('notes/create', { text, ...noteParams })).createdNote;
}, },
'note', msg => (msg as Misskey.entities.Note).text === text, 'note', (msg) => {
if (Misskey.note.isStreamNote(msg)) {
return false;
}
return msg.text === text;
},
channelParams, channelParams,
); );
strictEqual(streamingFired, expect); strictEqual(streamingFired, expect);

View File

@ -80,7 +80,7 @@ async function prepend(data: Misskey.entities.Note | Misskey.entities.StreamNote
let note: Misskey.entities.Note & MisskeyEntity; let note: Misskey.entities.Note & MisskeyEntity;
if ('_allowCached_' in data) { if (Misskey.note.isStreamNote(data)) {
let fullNote: Misskey.entities.Note | null = null; let fullNote: Misskey.entities.Note | null = null;
const { _allowCached_, ..._data } = data; const { _allowCached_, ..._data } = data;
@ -91,7 +91,7 @@ async function prepend(data: Misskey.entities.Note | Misskey.entities.StreamNote
credentials: 'omit', credentials: 'omit',
}); });
if (!res.ok) return; if (!res.ok) return;
fullNote = await res.json(); fullNote = (await res.json()) as Misskey.entities.Note;
} else { } else {
fullNote = await misskeyApi('notes/show', { fullNote = await misskeyApi('notes/show', {
noteId: data.id, noteId: data.id,

View File

@ -2359,6 +2359,9 @@ type ISigninHistoryResponse = operations['i___signin-history']['responses']['200
// @public (undocumented) // @public (undocumented)
function isPureRenote(note: Note): note is PureRenote; function isPureRenote(note: Note): note is PureRenote;
// @public (undocumented)
function isStreamNote(note: Note | StreamNote): note is StreamNote;
// @public (undocumented) // @public (undocumented)
export interface IStream extends EventEmitter<StreamEvents> { export interface IStream extends EventEmitter<StreamEvents> {
// (undocumented) // (undocumented)
@ -2652,7 +2655,8 @@ type Note = components['schemas']['Note'];
declare namespace note { declare namespace note {
export { export {
isPureRenote isPureRenote,
isStreamNote
} }
} }
export { note } export { note }
@ -3194,14 +3198,13 @@ export type StreamEvents = {
} & BroadcastEvents; } & BroadcastEvents;
// @public (undocumented) // @public (undocumented)
type StreamNote = ({ type StreamNote = {
id: Note['id']; id: Note['id'];
poll?: Pick<NonNullable<Note['poll']>, 'choices'>; poll?: Pick<NonNullable<Note['poll']>, 'choices'>;
reply?: Pick<NonNullable<Note['reply']>, 'myReaction'>; reply?: Pick<NonNullable<Note['reply']>, 'myReaction'>;
renote?: Pick<NonNullable<Note['renote']>, 'myReaction'>; renote?: Pick<NonNullable<Note['renote']>, 'myReaction'>;
} & {
_allowCached_: true; _allowCached_: true;
}) | { } | {
id: Note['id']; id: Note['id'];
_allowCached_: false; _allowCached_: false;
}; };

View File

@ -248,14 +248,13 @@ export type AnnouncementCreated = {
announcement: Announcement; announcement: Announcement;
}; };
export type StreamNote = ({ export type StreamNote = {
id: Note['id']; id: Note['id'];
poll?: Pick<NonNullable<Note['poll']>, 'choices'>; poll?: Pick<NonNullable<Note['poll']>, 'choices'>;
reply?: Pick<NonNullable<Note['reply']>, 'myReaction'>; reply?: Pick<NonNullable<Note['reply']>, 'myReaction'>;
renote?: Pick<NonNullable<Note['renote']>, 'myReaction'>; renote?: Pick<NonNullable<Note['renote']>, 'myReaction'>;
} & {
_allowCached_: true; _allowCached_: true;
}) | { } | {
id: Note['id']; id: Note['id'];
_allowCached_: false; _allowCached_: false;
}; };

View File

@ -1,4 +1,4 @@
import type { Note, PureRenote } from './entities.js'; import type { Note, StreamNote, PureRenote } from './entities.js';
export function isPureRenote(note: Note): note is PureRenote { export function isPureRenote(note: Note): note is PureRenote {
return ( return (
@ -10,3 +10,7 @@ export function isPureRenote(note: Note): note is PureRenote {
note.poll == null note.poll == null
); );
} }
export function isStreamNote(note: Note | StreamNote): note is StreamNote {
return '_allowCached_' in note && typeof note._allowCached_ === 'boolean';
}