From 1d3a92979f6d8fffbeedb60920aee4a8fd063dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Acid=20Chicken=20=28=E7=A1=AB=E9=85=B8=E9=B6=8F=29?= Date: Sun, 12 May 2019 22:20:31 +0900 Subject: [PATCH] Update parse.ts --- src/mfm/parse.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/mfm/parse.ts b/src/mfm/parse.ts index f8464121f..6ae17a9e8 100644 --- a/src/mfm/parse.ts +++ b/src/mfm/parse.ts @@ -2,18 +2,14 @@ import { mfmLanguage } from './language'; import { MfmForest } from './prelude'; import { normalize } from './normalize'; -export function parse(source: string | null): MfmForest | null { - if (source == null || source == '') { - return null; - } - - return normalize(mfmLanguage.root.tryParse(source)); +export function parse(source: T): T extends string ? MfmForest : null { + return typeof source === 'string' ? + normalize(mfmLanguage.root.tryParse(source)) : + null as any; } -export function parsePlain(source: string | null): MfmForest | null { - if (source == null || source == '') { - return null; - } - - return normalize(mfmLanguage.plain.tryParse(source)); +export function parsePlain(source: T): T extends string ? MfmForest : null { + return typeof source === 'string' ? + normalize(mfmLanguage.plain.tryParse(source)) : + null as any; }