You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Normally, TS will figure out if an imported type is incorrectly being used as a value.
When shorthand object creation is used, TS will miss the error.
⏯ Playground Link
I couldn't figure out how to use the playground since it depends on using multiple files (import/export).
I've created a minimal repro in this repo samouri/typescript-type-import-bug-repro, it is only ~10 LOC.
💻 Code
importtype{A}from'./a';// This correctly throwsconstobject1={A: A}// This should throw the error: "'A' cannot be used as a value because it was imported using 'import type'"constobject2={ A };
🙁 Actual behavior
No error is thrown
🙂 Expected behavior
An error should be thrown. Types should not be used where values are expected.
The text was updated successfully, but these errors were encountered:
samouri
changed the title
Import Types incorrectly allowed to be used as a value when object shorthand is used
Imported type incorrectly allowed to be used as a value when object shorthand is used
Jul 2, 2021
Strange, this seems to raise 2693 correctly in the TS bug workbench
// @errors: 2693// @filename: other.tsexporttypeA={thing: string}// @filename: index.tsimporttype{A}from'./other';// This should throw the error: "'A' cannot be used as a value because it was imported using 'import type'"constobject={ A };
If you change the type to a class then it will reproduce.
// @filename: other.tsexportclassA{}// @filename: index.tsimporttype{A}from'./other';// This should throw the error: "'A' cannot be used as a value because it was imported using 'import type'"constobject={ A };
Bug Report
Normally, TS will figure out if an imported type is incorrectly being used as a value.
When shorthand object creation is used, TS will miss the error.
⏯ Playground Link
I couldn't figure out how to use the playground since it depends on using multiple files (import/export).
I've created a minimal repro in this repo samouri/typescript-type-import-bug-repro, it is only ~10 LOC.
💻 Code
🙁 Actual behavior
No error is thrown
🙂 Expected behavior
An error should be thrown. Types should not be used where values are expected.
The text was updated successfully, but these errors were encountered: