質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

Q&A

0回答

1461閲覧

TypeScriptのLintのチェックでインスタンス変数が定義されていないエラー

退会済みユーザー

退会済みユーザー

総合スコア0

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

0グッド

2クリップ

投稿2019/01/27 13:03

typescirptでtslintを使用しています。

class HelloWorld { public name:string = 'hello' greet() { return 'hello' } }

上記のようなtsコードを書いた場合、なぜかnameが定義されていないとlintでエラーが出てしまいます。

TS2339: Property 'name' does not exist on type 'HelloWorld'.

eslintからパースしてチェックしている?感じです。
すみませんが、このあたりはあまり理解できていません。
状況としてはnuxtにtypescriptを導入し、typescriptにもlintを入れてチェックをしている感じです。
設定ファイルは以下のとおりです。

package.json

{ "version": "1.0.0", "description": "My exquisite Nuxt.js project", "private": true, "scripts": { "dev": "nuxt", "build": "nuxt build", "start": "nuxt start", "generate": "nuxt generate", "lint": "eslint --ext .js,.vue --ignore-path .gitignore .", "precommit": "npm run lint" }, "dependencies": { "cross-env": "^5.2.0", "nuxt": "^2.3.4", "@nuxtjs/axios": "^5.3.6", "vue": "latest" }, "devDependencies": { "nodemon": "^1.18.9", "@types/node":"^10.12.18", "@nuxtjs/eslint-config": "^0.0.1", "babel-eslint": "^8.2.1", "eslint": "^5.0.1", "eslint-config-standard": ">=12.0.0", "eslint-plugin-import": ">=2.14.0", "eslint-plugin-jest": ">=21.24.1", "eslint-plugin-node": ">=7.0.1", "eslint-plugin-promise": ">=4.0.1", "eslint-plugin-standard": ">=4.0.0", "eslint-loader": "^2.0.0", "typescript": "^3.2.4", "ts-loader": "^5.3.3", "eslint-plugin-vue": "^5.1.0", "typescript-eslint-parser": "^22.0.0", "eslint-plugin-prettier": "^3.0.1", "eslint-plugin-typescript": "^0.14.0" } }

.eslint.js

module.exports = { root: true, env: { browser: true, node: true }, parserOptions: { parser: 'babel-eslint' }, extends: [ '@nuxtjs' ], // add your custom rules here rules: {}, overrides: [ { files: ["*.ts", "*.vue"], parserOptions: { parser: "typescript-eslint-parser" }, plugins: ['vue', 'prettier', 'typescript', 'eslint-plugin-vue', 'eslint-plugin-prettier', 'eslint-plugin-typescript'] } ] }

tslint.json

{ "rules": { "adjacent-overload-signatures": true, "member-access": true, "member-ordering": [ true, { "order": [ "static-field", "instance-field", "constructor" ]}], "no-any": true, "no-empty-interface": true, "no-import-side-effect": true, "no-inferrable-types": true, "no-internal-module": true, "no-magic-numbers": true, "no-namespace": true, "no-non-null-assertion": true, "no-reference": true, "no-unnecessary-type-assertion": true, "no-var-requires": true, "only-arrow-functions": [ true ], "prefer-for-of": true, "promise-function-async": true, "typedef": [ true, "call-signature", "arrow-call-signature", "parameter", "arrow-parameter", "property-declaration", "variable-declaration", "member-variable-declaration", "object-destructuring", "array-destructuring" ], "typedef-whitespace": [ true, { "call-signature": "nospace", "index-signature": "nospace", "parameter": "nospace", "property-declaration": "nospace", "variable-declaration": "nospace" }, { "call-signature": "onespace", "index-signature": "onespace", "parameter": "onespace", "property-declaration": "onespace", "variable-declaration": "onespace" } ], "unified-signatures": true, "await-promise": true, "curly": [ true, "ignore-same-line" ], "forin": true, "import-blacklist": true, "label-position": true, "no-arg": true, "no-bitwise": true, "no-conditional-assignment": true, "no-console": [ false ], "no-construct": true, "no-debugger": true, "no-duplicate-super": true, "no-duplicate-variable": [ true, "check-parameters" ], "no-empty": true, "no-eval": true, "no-floating-promises": true, "no-for-in-array": true, "no-inferred-empty-object-type": true, "no-invalid-template-strings": true, "no-invalid-this": [ true, "check-function-in-method" ], "no-misused-new": true, "no-null-keyword": true, "no-object-literal-type-assertion": true, "no-shadowed-variable": true, "no-sparse-arrays": true, "no-string-literal": true, "no-string-throw": true, "no-submodule-imports": true, "no-switch-case-fall-through": true, "no-this-assignment": true, "no-unbound-method": true, "no-unsafe-any": true, "no-unsafe-finally": true, "no-unused-expression": true, "no-unused-variable": true, "no-use-before-declare": true, "no-var-keyword": true, "no-void-expression": [ true, "ignore-arrow-function-shorthand" ], "prefer-conditional-expression": [ true, "check-else-if" ], "prefer-object-spread": true, "radix": true, "restrict-plus-operands": true, "strict-boolean-expressions": true, "strict-type-predicates": true, "switch-default": true, "triple-equals": true, "typeof-compare": true, "use-default-type-parameter": true, "use-isnan": true, "cyclomatic-complexity": [ true, 6 ], "deprecation": true, "eofline": true, "indent": [ true, "spaces", 4 ], "linebreak-style": [ true, "LF" ], "max-classes-per-file": [ true, 1 ], "max-file-line-count": [ true, 300 ], "max-line-length": [ true, 120 ], "no-default-export": true, "no-duplicate-imports": true, "no-mergeable-namespace": true, "no-require-imports": true, "object-literal-sort-keys": true, "prefer-const": true, "trailing-comma": [ true, { "multiline": "never", "singleline": "never" }], "align": [ true, "parameters", "arguments", "statements", "members", "elements" ], "array-type": [ true, "array" ], "arrow-parens": [ true, "ban-single-arg-parens" ], "arrow-return-shorthand": [ true, "multiline" ], "binary-expression-operand-order": true, "callable-types": true, "class-name": true, "comment-format": [ true, "check-space", "check-uppercase" ], "completed-docs": [ true ], "encoding": true, "file-header": [ true, "Copyright \d{4}" ], "import-spacing": true, "interface-name": [ true, "never-prefix" ], "interface-over-type-literal": true, "jsdoc-format": true, "match-default-export-name": true, "newline-before-return": true, "new-parens": true, "no-angle-bracket-type-assertion": true, "no-boolean-literal-compare": true, "no-consecutive-blank-lines": [ true, 2 ], "no-irregular-whitespace": true, "no-parameter-properties": true, "no-reference-import": true, "no-trailing-whitespace": true, "no-unnecessary-callback-wrapper": true, "no-unnecessary-initializer": true, "no-unnecessary-qualifier": true, "number-literal-format": true, "object-literal-key-quotes": [ true, "always" ], "object-literal-shorthand": true, "one-line": [ true, "check-catch", "check-finally", "check-else", "check-open-brace", "check-whitespace" ], "one-variable-per-declaration": [ true, "ignore-for-loop" ], "ordered-imports": true, "prefer-function-over-method": true, "prefer-method-signature": true, "prefer-switch": true, "prefer-template": [ true, "allow-single-concat" ], "quotemark": [ true, "single", "avoid-template", "avoid-escape" ], "return-undefined": true, "semicolon": [ true, "always" ], "space-before-function-paren": [ true, "never" ], "space-within-parens": 0, "switch-final-break": [ true, "always" ], "type-literal-delimiter": true, "variable-name": [ true, "check-format", "ban-keywords" ], "whitespace": [ true, "check-branch", "check-decl", "check-operator", "check-module", "check-separator", "check-type", "check-typecast", "check-preblock" ] }, "defaultSeverity": "error" }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

papinianus

2019/01/28 06:29

定義だけでそのコードになるとは思いにくいのですが、利用側のコードはどうなっていますか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問