Typescript: Attaching property to exported function creates invalid definition file

Created on 30 Dec 2018  路  6Comments  路  Source: microsoft/TypeScript


TypeScript Version: 3.3.0-dev.20181229


Search Terms:
default export function property namespace

Code

export default function someFunc() {
    return 'hello!';
}

someFunc.someProp = 'yo';

Expected behavior:
The declaration file should be valid

Actual behavior:

packages/proj-1/build/index.d.ts:2:26 - error TS1005: ';' expected.

2 export default namespace someFunc {
                           ~~~~~~~~

packages/proj-1/build/index.d.ts:2:35 - error TS1005: ';' expected.

2 export default namespace someFunc {

Playground Link: Cannot be reproduced in the playground as the issue is in the d.ts file, not the JS. However, I've setup a repository: https://github.com/SimenB/tsc-b-auch

Related Issues: None found

Bug Declaration Emit Moderate Fixed help wanted

Most helpful comment

Haven't tried this, but you can probably get around this by writing

function someFunc() {
    return 'hello!';
}

someFunc.someProp = 'yo';

export default someFunc;

All 6 comments

Note that the file is generated successfully, it's only when trying to consume it things fall apart

Haven't tried this, but you can probably get around this by writing

function someFunc() {
    return 'hello!';
}

someFunc.someProp = 'yo';

export default someFunc;

Yeah, that works! Thanks 馃檪

Thanks @Kingwl!

Have the same issue.
@DanielRosenwasser Is this by design?

yarn tsc --version
Version 3.4.5

This is scheduled for 3.5.0. You can npm install typescript@next and if you're still seeing issues, open up a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Roam-Cooper picture Roam-Cooper  路  3Comments

blendsdk picture blendsdk  路  3Comments

bgrieder picture bgrieder  路  3Comments

siddjain picture siddjain  路  3Comments

dlaberge picture dlaberge  路  3Comments