Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TypeScript自动“作为常量”我的类型,导致错误_Typescript - Fatal编程技术网

TypeScript自动“作为常量”我的类型,导致错误

TypeScript自动“作为常量”我的类型,导致错误,typescript,Typescript,请参阅以下类型脚本代码: type Interpolation = null | undefined | boolean | number | string; type DefaultTheme = { color: { primary: { active: string; default: string; hover: string; disabled: string;

请参阅以下类型脚本代码:

type Interpolation = null | undefined | boolean | number | string;

type DefaultTheme = {
    color: {
        primary: {
            active: string;
            default: string;
            hover: string;
            disabled: string;
            background: string;
        };
        secondary: {
            active: string;
            default: string;
            hover: string;
            disabled: string;
            background: string;
        };
    };
};

type Classes<K extends string> = {
    [className in K]: string;
};

type Theme = DefaultTheme & {
    [key: string]: any;
};

type DynamicStyle<K extends string> = (
    theme: Theme,
    deps: any[],
    classes: Classes<K>,
) => Interpolation;

type Style<K extends string> = string | DynamicStyle<K>;

type Styles<K extends string> = ReadonlyArray<readonly [K, Style<K>]>;

function makeStyles<K extends string>(styles: Styles<K>) {
    return styles;
}

makeStyles([
    [
        'tag',
        (theme, [a, b, c]) => {
            return '';
        },
    ],
    ['label', ''],
]);

我知道这个问题,因为这一行
ReadonlyArray

这似乎缩小了我的类型

{
  "include": ["src", "types", "test"],
  "compilerOptions": {
    "target": "es5",
    "module": "esnext",
    "lib": ["dom", "esnext"],
    "importHelpers": true,
    "declaration": true,
    "sourceMap": true,
    "rootDir": "./",
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "moduleResolution": "node",
    "baseUrl": "./",
    "paths": {
      "*": ["src/*", "node_modules/*"]
    },
    "jsx": "react",
    "esModuleInterop": true
  }
}