-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
const
in ambient context incorrectly flagged as uninitialised
#3882
Comments
const
in ambient context incorrectly flagged as uninitialised
I'll fix this right away and publish a new verison. |
That was very quick!! Thanks @kdy1 👍 |
@kdy1 I've retested with v1.2.150 - but it seems the issue remains - at least when run against // file: types.d.ts
export const aThing: IAnInterface[];
export interface IAnInterface {
anAttribute: string;
anotherAttribute: boolean;
} // file: test_swc.js
const swc = require('@swc/core')
console.log(`swc version: ${swc.version}`)
const SWC_PARSE_OPTIONS = {
dynamicImport: true,
syntax: "typescript",
target: "es2022",
};
console.dir(
swc.parseFileSync('types.d.ts', SWC_PARSE_OPTIONS),
{depth:10}
)
|
For parseFile it's matter of option |
Hi @kdy1 that's what I expected as well. However, I've been looking for an option that'd work here, but weren't able to. parseFile (/ parseFileSync/ parse/ parseSync) takes a 2nd parameter of the type {
syntax: "typescript";
/**
* Defaults to `false`.
*/
tsx?: boolean;
/**
* Defaults to `false`.
*/
decorators?: boolean;
/**
* Defaults to `false`
*/
dynamicImport?: boolean;
comments?: boolean;
script?: boolean;
/**
* Defaults to es3.
*/
target?: JscTarget;
} Is it possible to pass more/ different things to the
|
It has a hidden field. |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the bug
Since #3742 was introduced in version 1.2.46 (issue: #3730), not only uninitialised. const declarations in 'strict' mode/ real code get flagged with
error: 'const' declarations must be initialized
but also those in ambient context (type declaration only/ .d.ts). However in ambient contexts aconst
cannot be initialised;tsc
will complain with a TS1039:Initializers are not allowed in ambient contexts.ts(1039)
Input code
Config
Playground link
https://play.swc.rs/?version=1.2.149&code=H4sIAAAAAAAAA1WMMQqEMBBF%2BznFnEB7U1nab7dYRHeigTAjyRd2Wby7Igjafd5%2FvLrmEJM0jN8ipfpUKCTfxTJ4NC1g%2F5qjTg13rXYKycGP8u4dXVa84MPgPzF7bYEchxVHvxxLJ3diwyz59g1mSbw62mgHJbEkGZAAAAA%3D&config=H4sIAAAAAAAAA0WOSw6DMAwF7%2BI1iyqLLrgDh4iCQakAR35GKoq4e0OgsPNvxi%2FTB4HaTMkrWI8K22L%2BSy3ZlhhBYzJqyFBGg5%2FADfUcRL2JglrTlfey9jqyFYjhXs4VYBIB38gclzhshz7InJSBZ%2BWXcfpf7sU1S78eg1wTVOe7CGEag93Y2XbS3%2Bjz5TqJ6C5VTfkDjgOVHewAAAA%3D
Expected behavior
In ambient contexts (type declaration files) uninitialised
const
declarations are allowed.Actual behavior
error: 'const' declarations must be initialized
Version
@swc/core 1.2.149
Additional context
The text was updated successfully, but these errors were encountered: