title: How to omit error : [ts] The inferred type of <class function name> references an inaccessible 'this' type. A type annotation is necessary
body: <p>I wanna create very nice, fluent typescript api, but I am getting
  error:</p>
  
  <blockquote>
    <p>[ts] The inferred type of 'firstLevelFunction' references an inaccessible 'this'
    type. A type annotation is necessary.</p>
  </blockquote>
  
  <p>My class schema:</p>
  
  <pre><code>class SomeClassAPI { 
  
      // in my case (on the picture at bottom)
      // 'firstLevelFunction(...)' equal 'replace(...)' method ,
      // from class CodeTransform  )
      public firstLevelFunction() { 
          const self = this; // ERROR
          // const self = this as any; // OK but not typechecking
  
          return {
              secondLevelFunction() {
                  return {
                      thirdLevelFunction() {
                          // ....
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Only if I am doing api with 'thirdLevelFunction' I am getting this thing.
  <strong>How can I omit this error</strong> ?</p>
  
  <p>my tsconfig.json</p>
  
  <pre><code>{
      "compileOnSave": true,
      "compilerOptions": {
          "declaration": true,
          "experimentalDecorators": true,
          "emitDecoratorMetadata": true,
          "allowSyntheticDefaultImports": true,
          "importHelpers": true,
          "module": "commonjs",
          "skipLibCheck": true,
          "sourceMap": true,
          "target": "es5",
          "typeRoots": [
              "node_modules/@types"
          ],
          "lib": [
              "dom",
              "es2015"
          ],
          "types": [
              "node"
          ],
          "rootDir": "./src",
          "outDir": "dist"
      },
      "include": [
          "src/**/*"
      ],
      "exclude": [
          "node_modules",
          "preview",
          "docs",
          "dist",
          "bundle",
          "example",
          "examples",
          "tests",
          "tmp-src"
      ]
  }
  </code></pre>
  
  <p>This is how error looks like in vscode:</p>
  
  <p><a href="https://i.stack.imgur.com/mJ4C6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mJ4C6.png" alt="enter image description here"></a></p>
  
  <p>I am using:</p>
  
  <ul>
  <li><strong>typescript</strong> 2.6.2</li>
  <li><strong>vscode</strong> 1.21.1</li>
  <li><strong>mac osx</strong> 10.13.3</li>
  </ul>