Skip to content

feat: tweaking our use of the no-use-before-define rule in TS#338

Merged
erunion merged 1 commit intomainfrom
ts/no-use-before-define
Mar 10, 2022
Merged

feat: tweaking our use of the no-use-before-define rule in TS#338
erunion merged 1 commit intomainfrom
ts/no-use-before-define

Conversation

@erunion
Copy link
Copy Markdown
Member

@erunion erunion commented Mar 10, 2022

🧰 What's being changed?

Slightly tweaks our no-use-before-define rule usage in the TS config to allow TS types that can be used before they're defined without errors.

For example, without this rule change the following code was throwing an error on ConfigOptions being used before it was defined even though TS is perfectly fine with where it's located in the file.:

import Oas from 'oas';
import APICore from './src/core';
import definition from './test/__fixtures__/simple.oas.json';

export default class SDK {
  spec: Oas;
  core: APICore;
  authKeys: (number | string)[][] = [];

  constructor() {
    this.spec = Oas.init(definition);
    this.core = new APICore(this.spec, 'api/1.0.0');
  }

  config(config: ConfigOptions) {
    this.core.setConfig(config);
  }
}

interface ConfigOptions {
  /**
   * By default we parse the response based on the `Content-Type` header of the request. You can
   * disable this functionality by negating this option.
   */
  parseResponse: boolean;
}

@erunion erunion added the enhancement New feature or request label Mar 10, 2022
// The stock `no-use-before-define` ESLint rule throws errors when TS interfaces, types, and
// enums are used before they're defined -- eventhough in TS that's OK.
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error'],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erunion erunion merged commit fc82044 into main Mar 10, 2022
@erunion erunion deleted the ts/no-use-before-define branch March 10, 2022 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants