Created
October 12, 2017 03:04
-
-
Save uzimith/326ee2140e7f84d6b088c74255cd0461 to your computer and use it in GitHub Desktop.
Object.assignエラー
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @flow */ | |
type Article = { | |
id: string | |
} | |
type State = { | |
articles: Article[] | |
} | |
const state: State = { | |
articles: [{ id: 'fuga' }] | |
} | |
const newArticle = [ | |
{ | |
id: 'hoge' | |
} | |
] | |
const article: Article[] = Object.assign([], state.articles, newArticle) | |
console.log(article) | |
// 31: const article: Array<Article> = Object.assign({}, state.articles, newArticle) | |
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call of method `assign`. Expected object instead of | |
// 31: const article: Array<Article> = Object.assign({}, state.articles, newArticle) | |
// ^^^^^^^^^^^^^^ array type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Article { | |
id: string | |
} | |
interface State { | |
articles: Article[] | |
} | |
const state: State = { | |
articles: [{ id: 'fuga' }] | |
} | |
const newArticle = [ | |
{ | |
id: 'hoge' | |
} | |
] | |
const article: Article[] = Object.assign({}, state.articles, newArticle) | |
console.log(article) | |
// {"0":{"id":"hoge"}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment