Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 10, 2022

Conversation

erunion
Copy link
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
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