TypeScript Version: 2.9.2
Search Terms: declaration file inline import, declaration files import path error
Code
In src/lib/operators/scalar.ts
export interface Scalar {
(): string
value: number
unit: Unit
add(value: Scalable): this
subtract(value: Scalable): this
multiply(value: Scalable): this
divide(value: Scalable): this
get(): string
toString(): string
}
export function scalar(value: string): Scalar {
return parseScalar(value) // returns an object of type scalar
}
In src/settings/spacing.ts
import { scalar } from '../lib/operators/scalar'
const baseSpacing = "14px"
export default {
get xs() {
return scalar(baseSpacing).divide(4) // returns an object of type Scalar
}
})
Expected behavior:
In dist/settings/spacing.d.ts
import {Scalar} from "../lib/operators/scalar"
export default {
readonly xs: Scalar
}
Actual behavior:
In dist/settings/spacing.d.ts
export default {
readonly xs: import("src/lib/operators/scalar").Scalar
}
NOTES:
- Should it import inline? (tslint complains that it shouldn't)
- The path should be "../lib/operators/scalar"
Local tsconfig.json
{
"extends": "./../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"paths": {
"*": ["node_modules/@types/*", "*"]
},
"outDir": "./dist",
"rootDir": "./src",
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"allowJs": false,
"declaration": true,
"jsx": "react",
"sourceMap": true
},
"include": ["./src/**/*"],
"exclude": [
"node_modules",
"src/**/__tests__/",
"build",
"dist",
"scripts",
"acceptance-tests",
"webpack",
"jest",
"src/setupTests.ts",
"webpack.config.js"
]
}
Main tsconfig.json
{
"compilerOptions": {
"baseUrl": "",
"module": "esnext",
"target": "es5",
"lib": ["dom", "esnext", "es6"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": false,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"paths": {
"@libs/components": ["Libs/Components/dist/index.js"]
}
}
}
TypeScript Version: 2.9.2
Search Terms: declaration file inline import, declaration files import path error
Code
In src/lib/operators/scalar.ts
In src/settings/spacing.ts
Expected behavior:
In dist/settings/spacing.d.ts
Actual behavior:
In dist/settings/spacing.d.ts
NOTES:
Local tsconfig.json
{ "extends": "./../../tsconfig.json", "compilerOptions": { "baseUrl": "./", "paths": { "*": ["node_modules/@types/*", "*"] }, "outDir": "./dist", "rootDir": "./src", "target": "es5", "module": "commonjs", "moduleResolution": "node", "allowSyntheticDefaultImports": true, "allowJs": false, "declaration": true, "jsx": "react", "sourceMap": true }, "include": ["./src/**/*"], "exclude": [ "node_modules", "src/**/__tests__/", "build", "dist", "scripts", "acceptance-tests", "webpack", "jest", "src/setupTests.ts", "webpack.config.js" ] }Main tsconfig.json
{ "compilerOptions": { "baseUrl": "", "module": "esnext", "target": "es5", "lib": ["dom", "esnext", "es6"], "sourceMap": true, "allowJs": true, "jsx": "react", "moduleResolution": "node", "rootDir": "src", "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, "noImplicitThis": true, "noImplicitAny": false, "strictNullChecks": true, "suppressImplicitAnyIndexErrors": true, "noUnusedLocals": true, "paths": { "@libs/components": ["Libs/Components/dist/index.js"] } } }