Repository navigation
Declaration files error for function return types #25685
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesThe issue relates to the emission of d.ts files
Milestone
Description
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"]
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts filesThe issue relates to the emission of d.ts files
Activity
DanielRosenwasser commentedon Jul 16, 2018
Can you see if this occurs in the nightlies or 3.0 RC?
Run the following for nightlies.
weswigham commentedon Jul 16, 2018
Afaik, you shouldn't set
"baseUrl"if you want a relative path generated. Is it set for a reason?robertontiu commentedon Jul 17, 2018
Wesley Wigham (@weswigham) I am using baseUrl because it apparently is required to run tsc.
Daniel Rosenwasser (@DanielRosenwasser) Same issue with typescript@next.
weswigham commentedon Jul 17, 2018
...? How so?
weswigham commentedon Jul 17, 2018
Oh, right, we require it be present when using
paths... According to our resolution rules, that import path we're generating is valid so long asbaseUrlis present, as the baseUrl indicates that the loader would resolve such paths correctly. Considering that you are using node module resolution and not an AMD loader, have you considered not setting either? It looks like your main tsconfig just attempts to reset the values your top-level tsconfig is setting, and that you're not actually using the paths map, really.robertontiu commentedon Jul 19, 2018
Wesley Wigham (@weswigham) I'm not entirly sure what you mean but I'll give it a go and post back the result. Thanks
ronp001 commentedon Aug 9, 2018
Wesley Wigham (@weswigham) I've encountered what seems to be a different manifestation of the same bug.
Code:
Expected Behavior:
in bug_f2.d.ts:
or at least:
Actual Behavior:
the import statement in bug_f2.d.ts includes the value from the paths directive:
Changing strict to false causes bug_f2.d.ts to take on the first form (i.e., param1: combinedType).
I saw this happening with 2.9.1, 2.9.2, 3.1.0-dev.20180809