2017-10-06 49 views
0

私はtypescriptを使い慣れており、このエラーを理解していません。私はそうのようArticleと呼ばれるクラスに引っ張っていた経路があります。上記のtryの2行目のプロパティ 'transformArticles'が型 'typeof Article'に存在しません

import { Request, Response } from "express"; 
const appRoot = require("app-root-path"); 
import { Article } from "./newsArticleModel"; 
const connection = require(appRoot + "/src/config/connection.ts"); 
const sql = require("mssql"); 




async function getNewsData() { 
    const pool = await connection; 
    const result = await pool.request() 
    .input("StoryID", sql.Int, 154147) 
    .execute("procedure"); 
    console.log(result, "the result from the stored procedure"); 
    return result; 
} 

sql.on("error", (err) => { 
    console.log("the error", err); 
}); 
export let index = async(req: Request, res: Response) => { 
    try { 
    let articles = await getNewsData(); 
    articles = Article.transformArticles(articles.recordset); 
    articles = JSON.stringify(articles); 
    res.render("home", { 
     articles, 
     title: "Home", 
    }); 
    } catch (e) { 
    console.log(e, "teh error"); 
    } 

}; 

を、私は次のエラーを取得する:Property 'transformArticles' does not exist on type 'typeof Article'.これは何を意味するのでしょうか?これは私のArticleクラスは次のようになります。

const appRoot = require("app-root-path"); 
import { TransformedRow } from "./transformedRowInterface"; 

export class Article { 
    transformArticles(articles) { 
    return articles.map((article) => { 
     return this.transformRows(article); 
    }); 
    } 

    transformRows(row) { 
    const transformedRow: TransformedRow = { 
     id: row.StoryID, 
     title: row.Title, 
     summary: row.Summary, 
     body: row.Body, 
     synopsis: row.Synopsis, 
     author: { 
     name: row.AuthorName, 
     email: row.AuthorEmail, 
     }, 
     impressions: row.ImpressionCount, 
     created: row.CreatedDate, 
     updated: row.UpdatedDate, 
    }; 
    return transformedRow; 
    } 

} 
+0

クラス名で結ばれた静的メンバとインスタンスと関数で結ばれた非静的メンバはプロトタイプです。 –

答えて

1

呼び出したい場合:

Articles.transformArticles(...); 

をあなたはメソッドがstaticにする必要があります。

export class Article { 
    static transformArticles(articles) { 

それとも、あなたはドンが」静的にしたい場合は、Articleのインスタンスを作成する

const article = new Article(); 
article.transformArticles(...); 
関連する問題