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

Broken in TypeScript < 4.7 #1227

Closed
ntucker opened this issue Mar 18, 2023 · 0 comments · Fixed by #1231
Closed

Broken in TypeScript < 4.7 #1227

ntucker opened this issue Mar 18, 2023 · 0 comments · Fixed by #1231
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: webpack 📦 Issue is related to webpack bundler cat: typings 👮 Typescript types related issues needs: complete repro 🖥️ Issue need to have complete repro provided

Comments

@ntucker
Copy link

ntucker commented Mar 18, 2023

Environment

  • Linaria version:

      "@linaria/babel-preset": "4.4.3",
      "@linaria/core": "4.2.8",
      "@linaria/react": "4.3.6",
      "@linaria/shaker": "4.2.9",
    
  • Bundler (+ version): webpack 5

  • Node.js version: 18

  • OS: ubuntu

Description

node_modules/@linaria/tags/types/utils/validateParams.d.ts:5:99 - error TS1005: '?' expected.

5 declare type GetParamByName<T> = T extends '*' ? Param : T extends (infer TNames extends ParamName)[] ? Extract<Param, readonly [TNames, ...unknown[]]> : T extends ParamName ? Extract<Param, readonly [T, ...unknown[]]> : never;
                                                                                                    ~

node_modules/@linaria/tags/types/utils/validateParams.d.ts:6:161 - error TS1005: '?' expected.

6 export declare type MapParams<TNames extends ParamConstraints, TRes extends Param[] = []> = TNames extends [infer THead, ...infer TTail extends ParamConstraints] ? THead extends '...' ? [...TRes, ...Params] : MapParams<TTail, [...TRes, GetParamByName<THead>]> : TRes;
                                                                                                                                                                  

This is because validateParams uses a 4.7 feature extends Constraints on infer Type Variables

Without this, only 4.1 is really needed (at least for parsing) as it introduced string template literals.

Reproducible Demo

Can't figure out how to set the TypeScript version in stackblitz, but literally any setup with just one import will trigger this with typescript 4.1

Solution

You can add an entry for types less than 4.7 . This could include the same types except one module that is changed to be more loose just so it works in 4.1

  "typesVersions": {
    ">=4.7": {
      "": [
        "lib/index.d.ts"
      ],
      "*": [
        "lib/index.d.ts"
      ]
    },
    ">=4.1": {
      "": [
        "ts4.1/index.d.ts"
      ],
      "*": [
        "ts4.1/index.d.ts"
      ]
    }
  },
@ntucker ntucker added bug report 🦗 Issue is probably a bug, but it needs to be checked needs: complete repro 🖥️ Issue need to have complete repro provided needs: triage 🏷 Issue needs to be checked and prioritized labels Mar 18, 2023
@github-actions github-actions bot added bundler: webpack 📦 Issue is related to webpack bundler cat: typings 👮 Typescript types related issues and removed needs: triage 🏷 Issue needs to be checked and prioritized labels Mar 18, 2023
@Anber Anber closed this as completed in 2e966f2 Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report 🦗 Issue is probably a bug, but it needs to be checked bundler: webpack 📦 Issue is related to webpack bundler cat: typings 👮 Typescript types related issues needs: complete repro 🖥️ Issue need to have complete repro provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant