Comments (2)
It's not quite clear to me if the duplicate identifier error itself is a bug— assignments of initializers that aren't function expressions are allowed to merge with the existing sybol declaration during binding: https://www.typescriptlang.org/play/?noUnusedLocals=true&install-plugin=typescript-playground-link-shortener#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVJxwAoBKALngDcctgBuAWAChRJYFUoBbEAZwAcoYBIkLwA3s3jSqseKmRcKUVAE9GTGbJhJUASVCpsiLCBjK1GrZTmJUAUQAe-OL165UF9cwC+zUTgAdApc8AC88ACMGijo2Hi6BiBGWCZmpBJ+TAGBdkkpaToReYbGpjAxhLkOzq7uCREZYQB8mRpAA
from typescript.
After some discussion within the team, we decided that this is in fact a bug.
In JS, this code makes m
a static method of f
:
function f() { }
f.m = () => 1
Which is a little questionable since m
isn't strictly speaking on the prototype the way most methods usually are. So it's not clear that it's worthwhile to mark it as such.
But it's definitely a bad idea in TS where you can have namespaces, because it results in a duplicate 'declaration':
function f() { }
declare namespace f {
export function m(): number
}
f.m = () => 1
both export function m
and f.m =
end up counting as declarations.
The narrow fix is to avoid binding f.m = () => 1
as a method in TS.
The wider fix is, I think, to stop binding f.m = () => 1
as a method even in JS. f.prototype.m = () => 1
should continue to be bound as a method but I think it's fine to represent f.m
as binding a property (whose type happens to be a function).
Both fixes boil down to deleting or conditionalising code in bindPotentiallyNewExpandoMemberToNamespace. The wider fix should make sure to continue binding prototype assignments as methods, so an additional parameter is probably needed if that's the way we want to go.
from typescript.
Related Issues (20)
- jsxRuntime pragma does not work
- ThisType doesn't enforce type-checking `Object.prototype.call` HOT 2
- ⚡ Performance: Project service doesn't cache all fs.realpath HOT 1
- `null` prop with `satisfies`, `strictNullChecks: false` + `noImplicitAny: true` gives any report HOT 4
- Debugging failure caused by lack of backtick(`)
- [proposal] Non widened string values should be valid enum values, like widened string values HOT 1
- 'Could not find source file' with Vue plugin when creating new files and using VS Code's file watcher HOT 7
- Contextual parameters inferred from overloads improvements
- Debug Failure caused by missing right parenthesis
- Assignment not correctly inferred when checking string literal. Variable X is used before being assigned HOT 1
- Omit utility doesn't respect methods on a type HOT 1
- The type of inference is inaccurate HOT 3
- Design Meeting Notes, 7/12/2024 HOT 1
- Design Meeting Notes, 7/16/2024 HOT 2
- Design Meeting Notes, 7/19/2024
- Inline comments always stripped from .d.ts, including @ts-expect-error, @ts-ignore etc. HOT 4
- TS2590 for simple ternary expression with large discriminated union HOT 1
- Allow customization of type display format in hover tooltips HOT 4
- Debug Failure caused by Invalid syntax(null) HOT 1
- Debug failure caused by incorrect identifier and undefined type
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typescript.