Skip to content

Commit 8bba5d3

Browse files
authored
Merge pull request #153 from xsnippet/interface-to-type
Add types for api and modes functions
2 parents 6aa1ef0 + 8986625 commit 8bba5d3

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

src/api/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import parseLinkHeader from 'parse-link-header'
22

33
import { getApiUri } from '../misc/url'
4-
import { Snippet, RawSnippet } from '../store'
4+
import { Snippet } from '../store'
55

66
export const fetchSnippet = (id: number): Promise<Snippet> => {
77
return fetch(getApiUri(`snippets/${id}`))
@@ -13,10 +13,10 @@ export const fetchSyntaxes = (): Promise<string[]> => {
1313
.then(response => response.json())
1414
}
1515

16-
export const fetchRecentSnippets = (marker: number): Promise<{ snippets: Snippet[], pagination: any}> => {
16+
export const fetchRecentSnippets = (marker: number): Promise<{ snippets: Snippet[], pagination: parseLinkHeader.Links | null}> => {
1717
let qs = ''
1818
if (marker) { qs = `&marker=${marker}` }
19-
let pagination = null
19+
let pagination: parseLinkHeader.Links
2020

2121
return fetch(getApiUri(`snippets?limit=20${qs}`))
2222
.then(response => {
@@ -26,7 +26,7 @@ export const fetchRecentSnippets = (marker: number): Promise<{ snippets: Snippet
2626
.then(snippets => ({ snippets, pagination }))
2727
}
2828

29-
export const postSnippet = (snippet: RawSnippet, onSuccess: (snippet: Snippet) => void, onError = () => {}): Promise<void> => {
29+
export const postSnippet = (snippet: Partial<Snippet>, onSuccess: (snippet: Snippet) => void, onError = () => {}): Promise<void> => {
3030
return fetch(getApiUri('snippets'), {
3131
method: 'POST',
3232
headers: {

src/misc/modes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import brace from 'brace'
22
import 'brace/ext/modelist'
33

4-
interface Mode {
4+
type Mode = {
55
caption: string;
66
extRe: RegExp;
77
extensions: string;
88
mode: string;
99
name: string;
1010
}
1111

12-
interface NormalizedSyntax {
12+
type NormalizedSyntax = {
1313
name: string;
1414
value: string;
1515
}

src/store/index.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { atom, selector, selectorFamily } from 'recoil'
33
import { fetchSnippet, fetchSyntaxes, fetchRecentSnippets } from '../api'
44
import { normalizedSyntaxes } from '../misc/modes'
55

6-
export interface Snippet {
6+
export type Snippet = {
77
content: string;
88
created_at: string;
99
id: number;
@@ -13,13 +13,6 @@ export interface Snippet {
1313
updated_at: string;
1414
}
1515

16-
export interface RawSnippet {
17-
content: string;
18-
syntax: string;
19-
tags: string[];
20-
title: string;
21-
}
22-
2316
export const recentSnippetsState = atom({
2417
key: 'recentSnippetsState',
2518
default: null,

0 commit comments

Comments
 (0)