Roaders / ts-command-line-args

A typescript wrapper for command-line-args that allow you to generate config from existing TS interfaces
26 stars 11 forks source link

error TS2344: Type 'T' does not satisfy the constraint '{ [name: string]: any; }' #34

Open mvaldes42 opened 1 year ago

mvaldes42 commented 1 year ago

Hi,

I have all these issues :

node_modules/ts-command-line-args/dist/contracts.d.ts:211:56 - error TS2344: Type 'T' does not satisfy the constraint '{ [name: string]: any; }'.

211 export declare type ParseOptions<T> = ArgsParseOptions<T> | PartialParseOptions | StopParseOptions;
                                                           ~

  node_modules/ts-command-line-args/dist/contracts.d.ts:211:34
    211 export declare type ParseOptions<T> = ArgsParseOptions<T> | PartialParseOptions | StopParseOptions;
                                         ~
    This type parameter might need an `extends { [name: string]: any; }` constraint.

node_modules/ts-command-line-args/dist/contracts.d.ts:271:31 - error TS2344: Type 'T' does not satisfy the constraint '{ [name: string]: any; }'.

271     arguments: ArgumentConfig<T>;
                                  ~

  node_modules/ts-command-line-args/dist/contracts.d.ts:270:38
    270 export declare type UsageGuideConfig<T = any> = {
                                             ~~~~~~~
    This type parameter might need an `extends { [name: string]: any; }` constraint.

node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:2:76 - error TS2344: Type 'T' does not satisfy the constraint '{ [name: string]: any; }'.

2 export declare function createCommandLineConfig<T>(config: ArgumentOptions<T>): CommandLineOption[];
                                                                             ~

  node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:2:49
    2 export declare function createCommandLineConfig<T>(config: ArgumentOptions<T>): CommandLineOption[];
                                                      ~
    This type parameter might need an `extends { [name: string]: any; }` constraint.

node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:3:67 - error TS2344: Type 'T' does not satisfy the constraint '{ [name: string]: any; }'.

3 export declare function normaliseConfig<T>(config: ArgumentConfig<T>): ArgumentOptions<T>;
                                                                    ~

  node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:3:41
    3 export declare function normaliseConfig<T>(config: ArgumentConfig<T>): ArgumentOptions<T>;
                                              ~
    This type parameter might need an `extends { [name: string]: any; }` constraint.

node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:3:88 - error TS2344: Type 'T' does not satisfy the constraint '{ [name: string]: any; }'.

3 export declare function normaliseConfig<T>(config: ArgumentConfig<T>): ArgumentOptions<T>;
                                                                                         ~

  node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:3:41
    3 export declare function normaliseConfig<T>(config: ArgumentConfig<T>): ArgumentOptions<T>;
                                              ~
    This type parameter might need an `extends { [name: string]: any; }` constraint.

node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:4:170 - error TS2344: Type 'T' does not satisfy the constraint '{ [name: string]: any; }'.

4 export declare function mergeConfig<T>(parsedConfig: Partial<T>, parsedConfigWithoutDefaults: Partial<T>, fileContent: Record<string, unknown>, options: ArgumentOptions<T>, jsonPath: keyof T | undefined): Partial<T>;
                                                                                                                                                                           ~

  node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:4:37
    4 export declare function mergeConfig<T>(parsedConfig: Partial<T>, parsedConfigWithoutDefaults: Partial<T>, fileContent: Record<string, unknown>, options: ArgumentOptions<T>, jsonPath: keyof T | undefined): Partial<T>;
                                          ~
    This type parameter might need an `extends { [name: string]: any; }` constraint.

node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:12:88 - error TS2344: Type 'T' does not satisfy the constraint '{ [name: string]: any; }'.

12 export declare function removeBooleanValues<T>(args: string[], config: ArgumentOptions<T>): string[];
                                                                                          ~

  node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:12:45
    12 export declare function removeBooleanValues<T>(args: string[], config: ArgumentOptions<T>): string[];
                                                   ~
    This type parameter might need an `extends { [name: string]: any; }` constraint.

node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:19:85 - error TS2344: Type 'T' does not satisfy the constraint '{ [name: string]: any; }'.

19 export declare function getBooleanValues<T>(args: string[], config: ArgumentOptions<T>): Partial<T>;
                                                                                       ~

  node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:19:42
    19 export declare function getBooleanValues<T>(args: string[], config: ArgumentOptions<T>): Partial<T>;
                                                ~
    This type parameter might need an `extends { [name: string]: any; }` constraint.

node_modules/ts-command-line-args/dist/helpers/markdown.helper.d.ts:6:79 - error TS2344: Type 'T' does not satisfy the constraint '{ [name: string]: any; }'.

6 export declare function createOptionsSections<T>(cliArguments: ArgumentConfig<T>, options: ParseOptions<any>): string[];
                                                                                ~

  node_modules/ts-command-line-args/dist/helpers/markdown.helper.d.ts:6:47
    6 export declare function createOptionsSections<T>(cliArguments: ArgumentConfig<T>, options: ParseOptions<any>): string[];
                                                    ~
    This type parameter might need an `extends { [name: string]: any; }` constraint.

node_modules/ts-command-line-args/dist/parse.d.ts:10:129 - error TS2344: Type 'T' does not satisfy the constraint '{ [name: string]: any; }'.

10 export declare function parse<T, P extends ParseOptions<T> = ParseOptions<T>, R extends boolean = false>(config: ArgumentConfig<T>, options?: P, exitProcess?: boolean, addCommandLineResults?: R): T & UnknownProperties<P> & CommandLineResults<R>;
                                                                                                                                   ~

  node_modules/ts-command-line-args/dist/parse.d.ts:10:31
    10 export declare function parse<T, P extends ParseOptions<T> = ParseOptions<T>, R extends boolean = false>(config: ArgumentConfig<T>, options?: P, exitProcess?: boolean, addCommandLineResults?: R): T & UnknownProperties<P> & CommandLineResults<R>;
                                     ~
    This type parameter might need an `extends { [name: string]: any; }` constraint.

Found 10 errors in 4 files.

Errors  Files
     2  node_modules/ts-command-line-args/dist/contracts.d.ts:211
     6  node_modules/ts-command-line-args/dist/helpers/command-line.helper.d.ts:2
     1  node_modules/ts-command-line-args/dist/helpers/markdown.helper.d.ts:6
     1  node_modules/ts-command-line-args/dist/parse.d.ts:10

I have " strict": true in my tsconfig.json. My type 'T' is as recommanded in the readme, like so :

 export interface IOptionsArguments {
  onlyWarnings: boolean;
  table: boolean;
  disableChecks: boolean;
}

it seems like "strictNullChecks": true specifically shows the issue.

I have to add "skipLibCheck": true for the check not to be performed and compile. My TS is "typescript": "^4.8.4" et tsc Version 4.9.3

Roaders commented 1 year ago

it's probably an issue with that version of TS. I don't think I have checks running for 4.8 yet.

charles-hill-work commented 1 year ago

I can confirm that it has to do with typescript 4.8.x, downgrading to 4.7.4 works for me. (Until the next time I blindly upgrade packages 😝)

Roaders commented 1 year ago

yes, Typescript does not follow semantic versioning so doing a compatible upgrade can actually break your app. I usually have ~ dependency ranges for TS rather than ^. I will get round to supporting 4.8 at some point...

Roaders commented 1 year ago

So I have added TS 4.8 and 4.9 to the testing list and all seems fine. Perhaps my compatibility test code is not complete enough. Can you share a repo with me that demonstrates the issue? Thanks