GetStream / stream-chat-js

JS / Browser Client - Build Chat with GetStream.io
https://getstream.io/chat/
Other
182 stars 76 forks source link

Cannot build node API due to typescript issues #1001

Closed prabir-vora closed 2 years ago

prabir-vora commented 2 years ago

My node API compilation fails while building using tsc. Getting 29 type errors in types.d.ts.

As mentioned in #834 and #841 I tried adding the "skipLibCheck": true and "lib": ["DOM"] flag to my tsconfig.json. I additionally event tried adding --skipLibCheck flag to my build command. However, the type files from stream-chat are not getting ignored.

Here is what my tsconfig.json looks like

{
    "compilerOptions": {
        "target": "es2018",
        "module": "commonjs",
        "lib": ["es2015", "es2018", "esnext.asynciterable", "DOM"],
        "skipLibCheck": true,
        "sourceMap": true,
        "outDir": "build",
        "rootDir": "./",
        "strictFunctionTypes": true,
        "noImplicitAny": true,
        "strictNullChecks": true,
        "noUnusedLocals": false,
        "noUnusedParameters": false,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "baseUrl": "./src",
        "paths": {
            "*": ["typings/*"],
            "@app/*": ["app/*"],
            "@service/*": ["services/*"],
            "@model/*": ["models/*"],
            "@helper/*": ["helpers/*"],
            "@module/*": ["modules/*"],
            "@library/*": ["lib/*"],
            "@config/*": ["configs/*"]
        },
        "types": ["mocha", "node"],
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "allowSyntheticDefaultImports": true,
        "resolveJsonModule": true
    },
    "exclude": ["**/dist", "**/node_modules", "**/*.spec.ts", "**/__tests__", "build", "bin", "node_modules"]
}

My build command is inside package.json is

"build": "tsc --skipLibCheck --project . --outDir ./bin",

vanGalilea commented 2 years ago

@prabir-vora thanks for reaching out, what version of typescript are you using?

prabir-vora commented 2 years ago

@prabir-vora thanks for reaching out, what version of typescript are you using?

@vanGalilea Earlier I was using version 3 but it didn't work. So I upgraded to the latest version 4.7.4 but no luck.

santhoshvai commented 2 years ago

@prabir-vora can you post the type errors that you get after upgrading to latest TS version please

prabir-vora commented 2 years ago

node_modules/stream-chat/dist/types/types.d.ts:411:37 - error TS1005: '>' expected.

411 i18n?: RequireAtLeastOne<Record<${TranslationLanguages}_text, string>> & {



node_modules/stream-chat/dist/types/types.d.ts:411:78 - error TS1109: Expression expected.

411     i18n?: RequireAtLeastOne<Record<`${TranslationLanguages}_text`, string>> & {
                                                                                 ~

node_modules/stream-chat/dist/types/types.d.ts:412:39 - error TS1005: ',' expected.

412         language: TranslationLanguages;
                                          ~

node_modules/stream-chat/dist/types/types.d.ts:414:22 - error TS1109: Expression expected.

414     latest_reactions?: ReactionResponse<StreamChatGenerics>[];
                         ~

node_modules/stream-chat/dist/types/types.d.ts:415:21 - error TS1109: Expression expected.

415     mentioned_users?: UserResponse<StreamChatGenerics>[];
                        ~

node_modules/stream-chat/dist/types/types.d.ts:416:19 - error TS1109: Expression expected.

416     own_reactions?: ReactionResponse<StreamChatGenerics>[] | null;
                      ~

node_modules/stream-chat/dist/types/types.d.ts:417:17 - error TS1109: Expression expected.

417     pin_expires?: string | null;
                    ~

node_modules/stream-chat/dist/types/types.d.ts:418:15 - error TS1109: Expression expected.

418     pinned_at?: string | null;
                  ~

node_modules/stream-chat/dist/types/types.d.ts:419:15 - error TS1109: Expression expected.

419     pinned_by?: UserResponse<StreamChatGenerics> | null;
                  ~

node_modules/stream-chat/dist/types/types.d.ts:419:50 - error TS1005: '(' expected.

419     pinned_by?: UserResponse<StreamChatGenerics> | null;
                                                     ~

node_modules/stream-chat/dist/types/types.d.ts:419:56 - error TS1005: ')' expected.

419     pinned_by?: UserResponse<StreamChatGenerics> | null;
                                                           ~

node_modules/stream-chat/dist/types/types.d.ts:420:21 - error TS1109: Expression expected.

420     reaction_counts?: {
                        ~

node_modules/stream-chat/dist/types/types.d.ts:421:13 - error TS1005: ']' expected.

421         [key: string]: number;
                ~

node_modules/stream-chat/dist/types/types.d.ts:421:21 - error TS1005: ',' expected.

421         [key: string]: number;
                        ~

node_modules/stream-chat/dist/types/types.d.ts:421:22 - error TS1136: Property assignment expected.

421         [key: string]: number;
                         ~

node_modules/stream-chat/dist/types/types.d.ts:421:30 - error TS1005: ',' expected.

421         [key: string]: number;
                                 ~

node_modules/stream-chat/dist/types/types.d.ts:423:21 - error TS1109: Expression expected.

423     reaction_scores?: {
                        ~

node_modules/stream-chat/dist/types/types.d.ts:424:13 - error TS1005: ']' expected.

424         [key: string]: number;
                ~

node_modules/stream-chat/dist/types/types.d.ts:424:21 - error TS1005: ',' expected.

424         [key: string]: number;
                        ~

node_modules/stream-chat/dist/types/types.d.ts:424:22 - error TS1136: Property assignment expected.

424         [key: string]: number;
                         ~

node_modules/stream-chat/dist/types/types.d.ts:424:30 - error TS1005: ',' expected.

424         [key: string]: number;
                                 ~

node_modules/stream-chat/dist/types/types.d.ts:426:17 - error TS1109: Expression expected.

426     reply_count?: number;
                    ~

node_modules/stream-chat/dist/types/types.d.ts:427:14 - error TS1109: Expression expected.

427     shadowed?: boolean;
                 ~

node_modules/stream-chat/dist/types/types.d.ts:428:12 - error TS1109: Expression expected.

428     silent?: boolean;
               ~

node_modules/stream-chat/dist/types/types.d.ts:429:12 - error TS1109: Expression expected.

429     status?: string;
               ~

node_modules/stream-chat/dist/types/types.d.ts:430:25 - error TS1109: Expression expected.

430     thread_participants?: UserResponse<StreamChatGenerics>[];
                            ~

node_modules/stream-chat/dist/types/types.d.ts:431:10 - error TS1109: Expression expected.

431     type?: MessageLabel;
             ~

node_modules/stream-chat/dist/types/types.d.ts:432:16 - error TS1109: Expression expected.

432     updated_at?: string;
                   ~

node_modules/stream-chat/dist/types/types.d.ts:433:1 - error TS1128: Declaration or statement expected.

433 };
    ~

Found 29 errors.
santhoshvai commented 2 years ago

Hey @prabir-vora, I created a test project. I can find the same 29 errors if I am on typescript v3.9, but not on typescript v4.7.4. Please make sure that you have properly reinstalled typescript. After changing the package.json, run npm install or yarn again. And then run your build command again.

jrista commented 1 year ago

I believe the issue is because of TypeScript strict mode. Strict mode enforces much more stringent typing requirements. This is now default in Angular since version 14, and strict mode provides a lot of value as it brings to the surface many issues at compile time that would otherwise blow up an app at runtime.