ILST: Fix/private constructor dom classes#160
Open
MBecherKurz wants to merge 1 commit into
Open
Conversation
Many Illustrator DOM classes cannot be instantiated from user code —
e.g. `new Layer()`, `new Document()`, `new PageItems()` all throw at
runtime ("does not have a constructor" or the class has no global).
These objects are handed to the script by the host: `app.documents`,
`doc.layers`, `app.preferences`, `doc.pageItems[0]`, etc.
The TypeScript typedef previously allowed `new X()` for every class,
which caught no misuse. `private constructor()` makes these misuses a
compile error while still letting the class name be used as a type.
Base classes Color and PageItem are intentionally left with a public
constructor so their existing subclasses (LabColor, PathItem, …) can
still extend them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Many Illustrator DOM classes cannot be instantiated from user code — e.g.
new Layer(),new Document(),new PageItems()all throw at runtime ("does not have a constructor" or the class has no global). These objects are handed to the script by the host:app.documents,doc.layers,app.preferences,doc.pageItems[0], etc. New instances can only be created through other Illustrator methods likeapp.activeDocument.layers.add()etc.The TypeScript typedef previously allowed
new X()for every class, which caught no misuse.private constructor()makes these misuses a compile error while still letting the class name be used as a type.Base classes Color and PageItem are intentionally left with a public constructor so their existing subclasses (LabColor, PathItem, …) can still extend them.
Note this was tested in the same ways as my other PR-159 with a short test script executed in Illustrator 2026 and 2025. But I'm quite sure that was already the case in older Illustrator versions.
The jsx script used to identify this.